且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Map-Reduce合并数据(MongoDb)

更新时间:2022-12-05 17:07:41

由于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中所需的字段来对L​​ogData中的数据进行非规范化.因此,您的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
}