集合中文档的结构如下:
{
"_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" : "Once Upon a Time in the West",
"year" : 1968,
"rated" : "PG-13",
"awards" : {
"wins" : 4
}
}
{
"title" : "A Million Ways to Die in the West",
"year" : 2014,
"rated" : "R",
"awards" : {
"wins" : 0
}
}
{
"title" : "Wild Wild West",
"year" : 1999,
"rated" : "PG-13",
"awards" : {
"wins" : 10
}
}
我想要这个:
{
"title" : "Once Upon a Time in the West",
"year" : 2013,
"rated" : "PG-13",
"awards" : {
"wins" : 0
}
}
{
"title" : "A Million Ways to Die in the West",
"year" : 2013,
"rated" : "PG-13",
"awards" : {
"wins" : 0
}
}
{
"title" : "Wild Wild West",
"year" : 2013,
"rated" : "PG-13",
"awards" : {
"wins" : 0
}
}
请告诉我,请求中需要更正哪些内容才能根据我的要求输出?
最后,就我而言,这是这样决定的:
或者像这样针对特定请求: