mongodb mongo Shell 中的查询给出 SyntaxError: missing : after property

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/38930207/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 20:48:03  来源:igfitidea点击:

query in mongo Shell gives SyntaxError: missing : after property

mongodbmongodb-querymongo-shell

提问by Computerlucaworld

db.movieDetails.find(
  { year: 2013, imdb.rating: Pg-13, award.wins: 0 },
  { title: 1, _id: 0 }
).pretty();

The mongo shell returns this error

mongo shell 返回此错误

2016-08-13T09:08:00.648+0200 E QUERY [thread1] SyntaxError: missing : after property id @(shell):1:60

2016-08-13T09:08:00.648+0200 E QUERY [thread1] SyntaxError: missing : after property id @(shell):1:60

Why? Thank you in advance!

为什么?先感谢您!

回答by tarashypka

If your query includes inner documents, then use quotes for them. Also, use quotes for querying String values

如果您的查询包含内部文档,则为它们使用引号。此外,使用引号查询字符串值

db.movieDetails.find(
  { year: 2013, "imdb.rating": "Pg-13", "award.wins": 0 },
  { title: 1, _id: 0 }
).pretty();