简体   繁体   中英

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

 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.

It is actually interpreted as 2 expressions with a minus ( - ) operator between them.

You can use db.getCollection('user-settings') to get it.

@MasterAM 是对的,另一种可能是

db["user-settings"].find()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM