Hi.
I am new to Mongo and have been given the following query to use, but my Mongo DB install is 3.4 and the query uses operators only available in 3.6 and above.
db.getCollection('events').aggregate([
{
$unwind: "$payload.latest"
},
{
$unwind: {
path: "$payload.authorisation.instrument"
}
},
{
$lookup: {
from: "request",
localField: "payload.uuid",
foreignField: "uuid",
as: "request"
}
},
{
$unwind: {
path: "$request"
}
},
{
$unwind: {
path: "$request.responses",
preserveNullAndEmptyArrays: true
}
},
{
$lookup: {
from: "questionSet",
localField: "request.questionSet",
foreignField: "uuid",
as: "set"
}
},
{
$unwind: {
path: "$set",
preserveNullAndEmptyArrays: true
}
},
{
$unwind: {
path: "$set.questions",
preserveNullAndEmptyArrays: true
}
},
{
$unwind: {
path: "$set.questions.responses",
preserveNullAndEmptyArrays: true
}
},
{
$match: {
$expr: {
$and: [
{ $eq: [ "$request.responses.questionId", "$set.questions.id" ] },
{ $eq: [ "$request.responses.responseId", "$set.questions.responses.id" ] }
]
}
}
},
{
$project: {
instr: "$payload.authorisation.instrument",
subjects: "$request.subjects",
purchaser: "$request.createdBy",
orderReference: "$request.submissionReference",
businessUnit: "$createdByBusinessUnit",
serviceCode: "$payload.latest.targeting.serviceCode",
bizCaseField1: "$request.bizCaseField1",
bizCaseField2: "$request.bizCaseField2",
bizCaseField3: "$request.bizCaseField3",
questions: {
questionText: "$set.questions.text",
responseText: "$set.questions.responses.name"
}
}
},
{ $group: {
_id: { id: "$_id", instr: "$instr", product: "$product" },
root: { $mergeObjects: '$$ROOT' },
questions: { $push: "$questions" }
}
},
{
$replaceRoot: {
newRoot: {
$mergeObjects: ['$root', '$$ROOT']
}
}
},
{
$project: {
_id: 0,
root: 0
}
},
{
$sort: {
instr: 1,
subjects: 1
}
}]).pretty();
I think it is the $expr and $mergeObjects operators that aren’t supported.
I’m not sure what to replace these with.
Any ideas please?