Reputation: 468
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
Upvotes: 1
Views: 349
Reputation: 2671
@MasterAM is right, the other way could be
db["user-settings"].find()
Upvotes: 5
Reputation: 16488
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.
Upvotes: 6