[英]meteor collection query in mongo console
I have a peer set up the collection's name to我有一个同行将集合的名称设置为
UserSettings = new Mongo.Collection("user-settings");
When I tried to query in MongoDB console, I am not able to do当我尝试在 MongoDB 控制台中查询时,我无法做到
db.user-settings.find()
i get this error :-我收到此错误:-
ReferenceError: settings is not defined
参考错误:未定义设置
How should I query a collection's name with dash?我应该如何使用破折号查询集合的名称?
Thanks谢谢
This is because user-settings
is not a valid identifier in JavaScript and as such cannot be used to access the field using the dot notation.这是因为
user-settings
不是 JavaScript 中的有效标识符,因此不能用于使用点符号访问字段。
It is actually interpreted as 2 expressions with a minus ( -
) operator between them.它实际上被解释为 2 个表达式,它们之间有一个减号 (
-
) 运算符。
You can use db.getCollection('user-settings')
to get it.您可以使用
db.getCollection('user-settings')
来获取它。
@MasterAM 是对的,另一种可能是
db["user-settings"].find()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.