I am trying to create join in mongodb collection.
My collection is 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]"
}
2nd collection OptimisationReport
{
"_id" : ObjectId("54dc51e2e043683f3f03fa9e"),
"OptimisationId" : 1,
"ScheduleLogId" : 10,
"ReportId" : 4113235,
"SubscriberPropertyId" : 10038,
"PropertyId" : 18166,
"ChannelId" : 701,
"CheckInDate" : "[2014/10/01]",
"LengthOfStay" : 1
}
based on OptimisationReport.ScheduleLogId=LogScheduler.ScheduleLogId, my new collection should be created e.g
newOptimisationReport{
....OptimisationReport data....
//since OptimisationReport.ScheduleLogId = 10
//since LogScheduler.ScheduleLogId = 10
// ADD LogScheduler data where LogScheduler.ScheduleLogId = 10
LogScheduler {
....logscheduler data....
}
}
I tried something like this
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);
}
);
but its not comparing the id's