JavaScript-вызовы
$ bin/mongo
> use mydb
> record1 = { key1: ‘value1’, key2: [1, 2, 3] }
> record2 = { key1: ‘value2’, key2: [4, 5, 6] }
> db.mycoll.save ( record1 )
> db.mycoll.save ( record2 )
> db.mycoll.find()
{ "_id" : ObjectId("4b8eb748230f141638cae177"), "key1" : "value1", "key2" : [ 1, 2, 3 ] }{ "_id" : ObjectId("4b8eb74d230f141638cae178"), "key1" : "value2", "key2" : [ 4, 5, 6 ] }
> db.mycoll.ensureIndex({key1: 1})
> db.mycoll.find({key1:'value1'}){ "_id" : ObjectId("4b8eb748230f141638cae177"), "key1" : "value1", "key2" : [ 1, 2, 3 ] }
> db.mycoll.update({key1:'value2'}, {'$set':{key3:'some other data'}})> db.mycoll.find(){ "_id" : ObjectId("4b8eb748230f141638cae177"), "key1" : "value1", "key2" : [ 1, 2, 3 ] }{ "_id" : ObjectId("4b8eb74d230f141638cae178"), "key1" : "value2", "key2" : [ 4, 5, 6 ], "key3" : "some other data" }