The issue I'm facing with Mongo involves an identifier in the forEach
loop within the second aggregation. Despite my best efforts, I cannot pinpoint which identifier is causing the problem. After staring at it all day, I realize that fresh eyes are needed to help me out. Any assistance will be greatly appreciated by my eyes, brain, and heart!
use events
var affected = []
var start = new Date()
var end = new Date("2017-06-01T00:00:00Z")
for (var dayPast = new Date(start); start >= end; start.setDate(start.getDate() - 1)) {
dayPast.setDate(dayPast.getDate() - 1)
var results = db.completion_event.aggregate([{
$match: {
applicationId: 1,
dateCreated: {
$lt: start,
$gte: dayPast
},
"data.name": "eventComplete",
"data.metadata.aggregationId": /identifying_string.*/,
"data.sponsorIds": {$in: [1,2,3,4,5,6]}
}
}, {
$project: {
customerId: 1,
dateCreated: 1,
"data.metadata.aggregationId": 1
}
}, {
$group: {
_id: {
customerId: "$customerId",
dateCreated: "$dateCreated",
aggregationId: "$data.metadata.aggregationId"
},
"total": {
$sum: 1
}
}
}], {
$limit: 1
}, {
allowDiskUse: true
}).toArray()
results.forEach(function(event) {
use rewards
var state = db.customer_state.find({customerId: event._id.customerId}).sort({_id: -1}).limit(1).toArray()[0]
var planId = state.planId
var plan = db.plan.find({id: planId}).toArray()[0]
if(plan.schedule.activeStart < new Date() < plan.schedule.activeEnd) {
use events
var latest = db.completion_event.aggregate([{
$match: {
applicationId: 1,
customerId: event._id.customerId,
dateCreated: {
$gte: plan.schedule.activeStart
},
"data.name": "outterEventComplete",
"data.metadata.aggregationId": event._id.aggregationId
}
},
{
$project: {
consumerId: 1,
dateCreated: 1,
"data.sponsorIds": 1,
"data.metadata.aggregationId": 1
}
}], {
$limit: 1
}).toArray()
affected.push(latest[0])
}
})
}
print(affected)
The source of my frustration:
E QUERY SyntaxError: Unexpected identifier