Thursday, December 11, 2014

mongo shell












16 MB limit for doc size

C:\WINDOWS\system32>mongo MongoDB shell version: 2.6.5 connecting to: test > show collections > db.foo.save({_id:1,x:10}) WriteResult({ "nMatched" : 0, "nUpserted" : 1, "nModified" : 0, "_id" : 1 }) > show collections foo system.indexes >
> db.bar.save({_id:1,x:10}) WriteResult({ "nMatched" : 0, "nUpserted" : 1, "nModified" : 0, "_id" : 1 }) > db.system.indexes.find() { "v" : 1, "key" : { "_id" : 1 }, "name" : "_id_", "ns" : "test.foo" } { "v" : 1, "key" : { "_id" : 1 }, "name" : "_id_", "ns" : "test.bar" } >


cannot use array for id

> db.users.save({name:'Bob'}) WriteResult({ "nInserted" : 1 }) > db.users.find() { "_id" : ObjectId("548a0667444e0f70ac382dfd"), "name" : "Bob" }

> ObjectID().getTImestamp() 2014-12-11T16:05:07.710-0500 ReferenceError: ObjectID is not defined > ObjectId() ObjectId("548a0718444e0f70ac382dfe") > ObjectId().getTImestamp() 2014-12-11T16:05:33.088-0500 TypeError: Object ObjectId("548a071d444e0f70ac382df f") has no method 'getTImestamp' > ObjectId().getTimestamp() ISODate("2014-12-11T21:05:54Z") >

2nd doc with the same id replaced the first


insert is safer


no id used


use email as id




save is dangerous



upsert, insert if



update


update


inc x and add y no problem


remove a field


rename a wrong field


array





not array












sort ID ascending



return id 1 which matched the criteria









No comments:

Post a Comment