MongoDB CLI 101 Fundamentals 

[Angel@localhost ~]$ mongo
> show collections; //equivalent to rdbms tables
> use test; //use test db
> db.test.count();
> db.test.find(); //all documents, a document is like a rdbms row.
> db.test.find({_id:ObjectId("52c351ffc5c629a6ca901ae5")});// where _id equals to...
> db.test.find({_id:ObjectId("52c351ffc5c629a6ca901ae5")},{'_id':0}); // _id field is not displayed
> db.test.update({_id:ObjectId("52c351ffc5c629a6ca901ae5")},{'field-to-update':'new-value'});//updating a field
> db.test.update({_id:ObjectId("52c351ffc5c629a6ca901ae5")},{$set:{'Year':2014}}); //add new field



[ view entry ] ( 1429 views )   |  print article

| 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 |


2024 By Angel Cool