-
shell
- db
- use database
- insert
- batchInsert
- update
-
Upserts
- insert or update
- remove
-
save
- if _id is exist it will update otherwise
-
help
- db.help()
- db.mycoll.help()
- ...
-
show
- show dbs
- show collections
- show users
- ...
-
modifier
- $set
-
$inc
- Incrementing
-
decrementing
- Subtopic 1
-
modifier array
- $push
- $addToSet
- $each
- $pop
- $pull
- db.getLastError()
-
Query
-
find
-
example
- db.users.find({"username" : "joe", "age" : 27})
- Specifying Which Keys to Return
-
Criteria
- $lt
- $lte
- $gt
- $gte
- $or
- db.raffle.find({"$or" : [{"ticket_no" : 725}, {"winner" : true}]})
- $in
- db.raffle.find({"ticket_no" : {"$in" : [725, 542, 390]}})
- $not
- db.users.find({"id_num" : {"$not" : {"$mod" : [5, 1]}}})
- $mod
- db.users.find({"id_num" : {"$mod" : [5, 1]}})
-
Conditional Semantics
- db.users.find({"age" : {"$lt" : 30, "$gt" : 20}})
- db.users.find({"$and" : [{"x" : {"$lt" : 1}}, {"x" : 4}]})
-
null
- list all
- db.c.find()
-
array
- one of them
- $all
- match all
- $size
- $slice
-
Embedded Documents
- Subtopic 1
- $where
- sort
- limit
- skip
-
_addSpecial
- $maxscan
- $min
- $max
- $showDiskLoc
-
Server-Side Scripting
-
turn javascript off
- running mongod with the --noscripting option.
- use parameters like sql
-
Cursors
-
open
- var cursor = db.collection.find();
- cursor.hasNext()
- obj = cursor.next();
- forEach
-
database command
- drop
-
data type
- null
- boolean
- number
- string
- date
- regular expression
- array
- embedded document
- object id
- binary data
-
code
- JavaScript code:
- Main Topic 3