如何限制 mongodb 中返回的嵌套数组字段
how to limit nested arrays field returned in mongodb
这是课程合集:
{
"_id": "RtPA6Cxs3fzJcGpgP",
"Seasons": [
{
"title": "intro",
"Episodes": [
{
"title": "what is c++?",
"length": "12:52",
"free_url": "free-episode-1.mp4"
},
{
"title": "why c++?",
"length": "05:20",
"paid_url": "premium-episode-1.mp4"
}
]
},
{
"title": "first season",
"Episodes": [
{
"title": "declare variables",
"length": "12:35",
"paid_url": "premium-episode-2.mp4"
},
{
"title": "pointers",
"length": "04:00",
"free_url": "free-episode-2.mp4"
}
]
}
]
}
我正在尝试获取(除 paid_urls 之外的所有内容):
{
"_id": "RtPA6Cxs3fzJcGpgP",
"Seasons": [
{
"title": "intro",
"Episodes": [
{
"title": "what is c++?",
"length": "12:52",
"free_url": "free-episode-1.mp4"
},
{
"title": "why c++?",
"length": "05:20"
}
]
},
{
"title": "first season",
"Episodes": [
{
"title": "declare variables",
"length": "12:35"
},
{
"title": "pointers",
"length": "04:00",
"free_url": "free-episode-2.mp4"
}
]
}
]
}
尝试了这些查询:
1. 这适用于客户端(chrome 控制台)但不适用于 "meteor mongo":
db.courses.find({_id: "RtPA6Cxs3fzJcGpgP"}, {fields: {"Seasons.Episodes.paid_url": 0}}).fetch()
我在 "meteor mongo" 上遇到的错误:
"$err" : "Can't canonicalize query: BadValue Unsupported projection option: fields: { Seasons.$.Episodes.$.paid_url: 0.0 }"`
也试过了:
Courses.find({_id: this.params.id}, {fields: {"Seasons.$.Episodes.$.paid_url": 0}});
这是正确的查询:
db.courses.find({_id: "RtPA6Cxs3fzJcGpgP"}, {"Seasons.Episodes.paid_url": 0}})
不需要字段
这是课程合集:
{
"_id": "RtPA6Cxs3fzJcGpgP",
"Seasons": [
{
"title": "intro",
"Episodes": [
{
"title": "what is c++?",
"length": "12:52",
"free_url": "free-episode-1.mp4"
},
{
"title": "why c++?",
"length": "05:20",
"paid_url": "premium-episode-1.mp4"
}
]
},
{
"title": "first season",
"Episodes": [
{
"title": "declare variables",
"length": "12:35",
"paid_url": "premium-episode-2.mp4"
},
{
"title": "pointers",
"length": "04:00",
"free_url": "free-episode-2.mp4"
}
]
}
]
}
我正在尝试获取(除 paid_urls 之外的所有内容):
{
"_id": "RtPA6Cxs3fzJcGpgP",
"Seasons": [
{
"title": "intro",
"Episodes": [
{
"title": "what is c++?",
"length": "12:52",
"free_url": "free-episode-1.mp4"
},
{
"title": "why c++?",
"length": "05:20"
}
]
},
{
"title": "first season",
"Episodes": [
{
"title": "declare variables",
"length": "12:35"
},
{
"title": "pointers",
"length": "04:00",
"free_url": "free-episode-2.mp4"
}
]
}
]
}
尝试了这些查询: 1. 这适用于客户端(chrome 控制台)但不适用于 "meteor mongo":
db.courses.find({_id: "RtPA6Cxs3fzJcGpgP"}, {fields: {"Seasons.Episodes.paid_url": 0}}).fetch()
我在 "meteor mongo" 上遇到的错误:
"$err" : "Can't canonicalize query: BadValue Unsupported projection option: fields: { Seasons.$.Episodes.$.paid_url: 0.0 }"`
也试过了:
Courses.find({_id: this.params.id}, {fields: {"Seasons.$.Episodes.$.paid_url": 0}});
这是正确的查询:
db.courses.find({_id: "RtPA6Cxs3fzJcGpgP"}, {"Seasons.Episodes.paid_url": 0}})
不需要字段