Search code examples
javascriptmongodbmeteornosql

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


Solution

  • 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.