Yumiko
Yumiko

Reputation: 468

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

Upvotes: 1

Views: 349

Answers (2)

Harpreet Singh
Harpreet Singh

Reputation: 2671

@MasterAM is right, the other way could be

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

Upvotes: 5

MasterAM
MasterAM

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

Related Questions