我可以帮您进行翻译。这段内容是关于文档集合结构的描述,大致意思如下:
我正在尝试使用投影并添加一些额外参数来获取特定字段的内容。我想要获取这些键的值:
我这样写
我想要像这样的输出,例如:
告诉我,如何修改查询以满足我的具体要求...感谢大家的帮助。
我的文档集合结构如下:
{
"_id" : ObjectId("569190cd24de1e0ce2dfcd62"),
"title" : "Star Trek II: The Wrath of Khan",
"year" : 1982,
"rated" : "PG",
"released" : ISODate("1982-06-04T04:00:00Z"),
"runtime" : 113,
"countries" : [
"USA"
],
"awards" : {
"wins" : 2,
"nominations" : 9,
"text" : "2 wins & 9 nominations."
}
}
我正在尝试使用投影并添加一些额外参数来获取特定字段的内容。我想要获取这些键的值:
title
,year
,rated
和awards
(并删除_id
)。我这样写
db.movieDetails.find( {}, {title: 1, year: 2013, rated: "PG-13", _id: 0, "awards.wins": 1 }).pretty()
来获取带有值的字段,但控制台显示不同的参数:{
"title" : "Star Trek II: The Wrath of Khan",
"year" : 1982,
"rated" : "PG",
"awards" : {
"wins" : 2,
}
}
我想要像这样的输出,例如:
{
"title" : "Star Trek II: The Wrath of Khan",
"year" : 2013,
"rated" : "PG-13",
"awards" : {
"wins" : 0
}
}
告诉我,如何修改查询以满足我的具体要求...感谢大家的帮助。
db.movieDetails.aggregate([ {$project: { title:1, _id:0, year: 2013, rated: "PG-13", "awards.wins": 0 } } ]) assert: command failed: { "ok" : 0, "errmsg" : "Bad projection specification, cannot exclude fields other than '_id' in an inclusion projection: { title: 1.0, _id: 0.0, year: 2013.0, rated: \"PG-13\", awards.wins: 0.0 }", "code" : 40178, "codeName" : "Location40178" } : aggregate failed
。 - invzbl3