Open the MongoDB client
Bin/mongo-port port number under installation directory
View Database
Show DBS;
Go to a database below
Use dbname;
View Collections
Show collections;
View collection All data
Db.collectionname.find ();
View collection One piece of data
Db.collectionname.findOne ();
Inserting data into a collection
Single: Db.collectionname.save ({"col1": "One"},{"col2": "22"});
Multiple bars: for (var i=1;i<10;i++) Db.collectionname.save ({x:4,j:i});
Close MongoDB Service
Use admin;
Db.shutdownserver ();
Query data with criteria
Db.collectionname.find ({condition});
Modify Operation
Db.collectionname.update ({condition},{$set: {j: "44"}});
Delete operation
Db.collectionname.remove ({condition})
Create a database
Use dbname; Description: Need to create a collection this Coucay created successfully
Deleting a database
Use dbname;
Db.dropdatabase ();
Delete Collection
Db.collectionname.drop ();
View Replica set Status
Rs.status ()
View from library status
Db.printslavereplicationinfo ()
Settings can be queried from the library
Db.getmongo (). Setslaveok ()
Create an index
Db.collectionname.ensureIndex ({field name: 1})
View Index
Db.collectionname.getIndexes ();
Delete Index
Db.collectionname.dropIndex ({field name: 1})
Rebuilding indexes
Db.aa.reIndex ();
View execution plans
Db.collectionname.find (). explain ();
MongoDB Basic Syntax