Skip to content

Instantly share code, notes, and snippets.

@notgiorgi
Last active June 19, 2016 15:19
Show Gist options
  • Save notgiorgi/3b5935250559428f67ac206dacd57a57 to your computer and use it in GitHub Desktop.
Save notgiorgi/3b5935250559428f67ac206dacd57a57 to your computer and use it in GitHub Desktop.
// Get all products of category with _id:0 and it's child categories
// category : {
// _id : Number,
// name : String,
// ancestors : Array<_id>
// }
var cursor = db.collection('categories').find({ ancestors : 0 });
cursor.forEach((doc) => {
db.collection('products').find({ category : doc._id });
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment