加入mongodb的收藏

时间:2015-02-16 17:25:26

标签: sql mongodb join

我正在尝试在mongodb集合中创建连接。

我的收藏是LogScheduler

{
"_id" : ObjectId("54dc5181e043683f3f03f87b"),
"ScheduleLogId" : 10,
"ScheduleId" : 9,
"SubscriberPropertyId" : 47984,
"SubscriberPropertyName" : "NA",
"StartDateTime" : "[2014/09/24:12:00:00 AM]",
"DaysOfData" : 125,
"Status" : 4,
"CreatedDate" : "[2014/09/24:12:33:00 PM]",
"ModifiedDate" : "[2014/09/24:12:33:11 PM]"
}

第二个集合OptimisationReport

{
"_id" : ObjectId("54dc51e2e043683f3f03fa9e"),
"OptimisationId" : 1,
"ScheduleLogId" : 10,
"ReportId" : 4113235,
"SubscriberPropertyId" : 10038,
"PropertyId" : 18166,
"ChannelId" : 701,
"CheckInDate" : "[2014/10/01]",
"LengthOfStay" : 1
}

基于OptimisationReport.ScheduleLogId = LogScheduler.ScheduleLogId,我应该创建新的集合,例如

newOptimisationReport{
 ....OptimisationReport data....
 //since OptimisationReport.ScheduleLogId = 10
//since LogScheduler.ScheduleLogId = 10
// ADD LogScheduler data where LogScheduler.ScheduleLogId = 10
LogScheduler {

            ....logscheduler data....

}
}

我试过这样的事情

db.Subscription_OptimisationReports.find().forEach(
function (newSubscription_OptimisationReports) {
    newSubscription_OptimisationReports.ScheduleLogId = db.Log_Scheduler.findOne( {"ScheduleLogId": newSubscription_OptimisationReports.ScheduleLogId} );
    db.newSubscription_OptimisationReports.insert(newSubscription_OptimisationReports);
}
);

但它没有比较id的

0 个答案:

没有答案