Reputation: 305
Excuse my ignorance but it is possible to get distinct tag attribute with all the links in one query? I know you can using .distinct('tag') but then I need to send the data twice which require querying the same link again
I have the following schema
var Link = new Schema({
title:{type:String, required:true},
url:{type:String, required:true},
tag:[{type: String,required:true}],
});
link
.find({})
.exec(function(err,q){
res.json(q);
});
Upvotes: 0
Views: 391
Reputation: 17453
In case you need all URLs per tag:
db.link.aggregate({
$group : {
_id : "$tag",
links: { $addToSet: "$url" }
}
})
Upvotes: 2