Skip to content

Instantly share code, notes, and snippets.

@A
Created March 22, 2014 11:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save A/9705337 to your computer and use it in GitHub Desktop.
Save A/9705337 to your computer and use it in GitHub Desktop.
module.exports = function () {
var ObjectId = mongoose.Schema.ObjectId;
return function (req, res) {
mongoose
.model('Project')
.aggregate({
'$match': {
'pages.texts._id': ObjectId(req.params.componentID)
}
})
.unwind('$pages')
.unwind('$pages.texts')
.aggregate({
'$match': {
'pages.texts._id': ObjectId(req.params.componentID)
}
})
.group({
'_id': '$_id',
'texts': {
'$push': '$pages.texts'
}
})
.exec(function (err, res) {
console.log(err);
console.log(res);
});
};
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment