问题描述
我有两个收藏夹.
LogData
[{
"SId": 10,
"NoOfDaya" : 9,
"Status" : 4
}
{
"SId": 11,
"NoOfDaya" : 8,
"Status" : 2
}]
OptData
[ {
"SId": 10,
"CId": 12,
"CreatedDate": ISO(24-10-2014)
}
{
"SId": 10,
"CId": 13,
"CreatedDate": ISO(24-10-2014)
}]
现在使用mongoDB,我需要以
Now using mongoDB I need to find the data in form
select a.SPID,a.CreatedDate,CID=(MAX(a.CID)) from OptData a
Join LogData c on a.SID=c.SID where Status>2
group by a.SPID,a.CreatedDate
LogData具有600条记录,而OPTData具有9000万条生产记录.我需要经常更新LogData,这就是为什么在单独的集合中.
LogData have 600 records whereas OPTData have 90 millions records in production. I need to update LogData frequently, that's why its in separate collection.
- 请不要建议将数据保存在一个集合中.
- 这是相同的查询,我用不同的方法问过在GridFs中创建文件( MongoDb)
- 请不要建议不能在mongoDB中应用联接.
推荐答案
由于MongoDB不支持JOIN,因此您将必须执行两个单独的查询并在应用程序层执行JOIN.仅有600个文档,LogData集合非常小,因此将其完全加载到应用程序内存中并使用它来丰富OptData返回的结果应该没问题.
Because MongoDB does not support JOINs, you will have to perform two separate queries and do the JOIN on the application layer. With just 600 documents the collection LogData is very small, so it should be no problem to completely load it into your applications memory and use it to enrich the results returned from OptData.
另一种选择是通过在OptData中各个文档中镜像LogData中所需的字段来对LogData中的数据进行非规范化.因此,您的OptData文档将如下所示:
Another option would be to denormalize the data from LogData by mirroring the fields you need from LogData in the respective documents in OptData. So your OptData documents would look something like this:
{
"SId": 10,
"CId": 12,
"CreatedDate": ISO(24-10-2014),
"LogStatus": 2
}
这篇关于Map-Reduce合并数据(MongoDb)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!