This is my schema
var Schema = new Schema{
name:String
topics:[{item:{type: ObjectId, ref: 'tag'},comment:String}]
}
So 'topics' field contains an array of embedded docs. Each of those contains a ref and a string 'comment'. There is a way I can find a specific ref id (the item field)?
I tried some projection but this make some sense don't you think? Obiouvsly doesn't work..:)
Model
.find(
{ topics: {
$in: [{ item: ObjectId("56e0aa684e7c55c414a51d82") }]
}
},{name:1})
.exec(function(err, data) {
res.json(data)
});
EDIT: I came up with this solution:
Model
.find(
{'topics':
{$elemMatch :
{
item: "56e0aa684e7c55c414a51d82"
}
}
}
)
.exec(function(err, data) {
res.json(data)
});