// MongoDb User Object:
const new_schema = new Schema({
name: {
first: {type: String},
last: {type: String},
},
currentPrivateLocation: {type: [String], default: []}
});
// Aggregation:
let pipeline = [{
$match: query
}];
pipeline.push({
$sort: sortObj
});
pipeline.push({
$group: {
_id: null,
count: {$sum: 1},
result: {$push: '$$ROOT'},
}
});
pipeline.push({
$project: {
_id: 0,
count: 1,
result: {
$slice: ['$result', Number(limit * (page - 1)), limit]
}
}
});
In MongoDB, I aggregate a collection to get the data in this format:
{
count: 2,
result:
[
{ _id: 57e55d55d9a7041100ac5e26,
subjectIds: [Object],
role: [Object]
},
{ _id: 58e5d545g9a7041500ac4526,
subjectIds: [Object],
role: [Object]
}
]
}
I now want to do a $lookup
based on the _id
of the objects inside 'result'
. When I try to $unwind
result, it just turns the result array into a result object with only the first element.
Any thoughts?