1
我有一個subdoc Id
,我需要使用Mongoose
和MongoDB
返回parent Doc
。我在這裏讀到:MongoDB: How to find by subdocument ID?,我應該可以使用Polls.find({'options': id}
,但它返回任何空數組而不是適當的文檔。從Mongoose中的subdoc ID查找父文件
架構
var Polls = new Schema({
name: String,
options: [{
name: String,
count: Number
}]
}
樣品投票
{
"_id": {
"$oid": "58ac963a8a84500de89c1080"
},
"name": "Here is one Poll",
"options": [
{
"name": "This is the first one",
"count": 0,
"_id": {
"$oid": "58ac963a8a84500de89c1083"
}
},
{
"name": "Second One",
"count": 0,
"_id": {
"$oid": "58ac963a8a84500de89c1082"
}
}
],
"__v": 0
}
能否請您發表您的查詢? –