node.js - Mongoose distinct query -
Forgive my ignorance, but it is possible to get different tag attributes with all the links in a query? I know that you can use .distinct ('tag') but then I need to send the data twice, for which I have to ask a single link again
I have to Schema is
Var link = new schema ({title: {type: string, required: true}, url: {type: string, required: true}, tag: [{type: string , Required: true}],}); Link .Fund ({}) .exec (function (mistake, q) {res.json (q);});
If you need all the URLs per tag:
db.link.aggregate ({$ group: {_id: "$ tag", link: {$ addToSet: "$ url"}}})
Comments
Post a Comment