#MongoDB
What is mongo - document based database, no SQL How do you install it by default its not secure, you should add a user and restrict access before production
digital ocean mongo labs using mongoLabs mongo ds021671.mlab.com:21671/sdcs -u michael -p michael robo mongo
local use db .find({filter}, {projection})
db.collection.find({ age: { $gt: 10}}, {history:0}) projection (limit the fields returned, cant include and exclude)
.insert({})
.insert( [ { "name": "banana", "color": "yellow", "number": 8 }, { "name": "grape", "color": "green", "number": 1020, "foodGroup": { "size": "small", "healthy": true, "snack": true } }, { "name": "peach", "color": "pink", "number": 1020, "foodGroup": { "size": "medium", "healthy": true, "snack": true } } ])
.insert({"foodGroup.size":"medium"},{ $set: { "name": “pear”, "color”:"green" } })
.remove() .count() .sort({name: 1}) .limit(2) .pretty()
cursors (how queries are executed, so it can be done in one request (call) when connecting the the db)
.sort({name: 1}) .limit(5) .pretty()
queries for record by object id
ObjectId() Returns a new ObjectId value. The 12-byte ObjectId value consists of:
- a 4-byte value representing the seconds since the Unix epoch,
- a 3-byte machine identifier,
- a 2-byte process id, and
- a 3-byte counter, starting with a random value.