Edit: This is not a javascript question. This is my observation on the Mongodb console.
I am a newbee to Mongodb, a bit confused about the syntax for query commands.
Some commands require quotes and some do not. Here is an example:
Insert one item:
db.users.insert( { "name": "Ben Bautista", "contact": "987648711", "address": [ { "building": "22 A, Bluemoon Apt", "zipcode": 90211 }, { "building": "170 A, Crompton Apt", "zipcode": 50910 }
] } )
Query:
The query for name works with or without quotes. But the query for nested item address.building throws a syntax error when no quotes used. (The third query below throws error).
Is there any guideline for querying nested items?
db.users.find({name:/Ben/})
db.users.find({"name":/Ben/})
db.users.find({address.building:/Bluemoon/})
db.users.find({"address.building":/Bluemoon/})