As an example,either of these will work:
db.wands.insert({"name": "Dream Bender", "creator": "Foxmond"})
db.wands.insert({name: "Dream Bender", creator: "Foxmond"})
Which one will I use any why?
Use the $in Operator to Match Values This query selects all documents in the inventory collection where the value of the quantity field is either 5 or 15. Although you can write this query using the $or operator, use the $in operator rather than the $or operator when performing equality checks on the same field.
Running SQL statements against a MongoDB collection. An SQL SELECT statement typically retrieves data from tables in a database, much like a mongo shell find statement retrieves documents from a collection in a MongoDB database.
The MongoDB $where operator is used to match documents that satisfy a JavaScript expression. A string containing a JavaScript expression or a JavaScript function can be pass using the $where operator.
MongoDB provides different types of comparison operators and less than operator ( $lt ) is one of them. This operator is used to select those documents where the value of the field is less than (<) the given value. You can use this operator in methods like, find() , update() , etc.
You can use quotes and never have to worry about when they are necessary.
When you run a query or command from the mongo shell interface it is being parsed by the shell's JavaScript interpreter.
Anything which isn't valid JavaScript will cause a syntax error.
For example, A collection or field name starting without an underscore or alpha character would have to be quoted.
So, either of these will work:
db.wands.insert({"name": "Dream Bender", "creator": "Foxmond"})
db.wands.insert({name: "Dream Bender", creator: "Foxmond"})
Also, this would work:
db.wands.insert({"3name": "Dream Bender", "creator": "Foxmond"})
But this won't work.
db.wands.insert({3name: "Dream Bender", creator: "Foxmond"})
So, I find it easier to be in the habit of using quotes so you don't have to remember the exceptions.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With