Access database: MONGO
- View all Databases:> show DBS
> show Dbsadmin (empty) local 0. 031GBnutch 0. 031GBtest (empty)
- Create/Switch database:> use Nutch
- View Database:> Db.stats ()
- View database Tables:> db.posts.stats ()
[email protected] mongodb]# Mongomongodb Shell version:2.6.7Connecting To:test>Use nutchswitched to DB Nutch>db.stats () {"DB":"Nutch",//Current database name "Collections":3,//How many tables are in the current database "Objects": One,//Current Database All tables how many data "avgobjsize":176,//average size of each piece of data "datasize":1936,//total size of all data "storagesize":24576,//disk size for all data "numextents":3, "Indexes":1,//Number of indexes "indexsize":8176,//Index Size "fileSize":16777216,//file size pre-allocated to the database "Nssizemb": -, "datafileversion" : { "Major":4, "Minor":5 }, "extentfreelist" : { "Num":0, "totalsize":0 }, "OK":1}>db.posts.stats () {"OK":0,"errmsg":"Collection [nutch.posts] not found." }>
- Delete the currently used database: >db.dropdatabase ();
- View the database currently in use: >db.getname (); >db;
The DB and GetName methods are the same effect and can query the currently used database
- Current DB version: Db.version ();
- Error message before query: Db.getpreverror ();
- Clear Error Logging: Db.reseterror ();
User-related
1. Add a user
Db.adduser ("name");
Db.adduser ("UserName", "pwd123", true); Add user, set password, read-only
2, database authentication, security mode
Db.auth ("UserName", "123123");
3. Show all current users
Show Users;
4. Delete users
Db.removeuser ("UserName");
Collection Aggregation Collection
1. Create a Clustered collection (table)
Db.createcollection ("Collname", {size:20, Capped:5, max:100});
2. Get a clustered collection with the specified name (table)
Db.getcollection ("account");
3. Get all the aggregation sets of the current DB
Db.getcollectionnames ();
4. Displays the status of all clustered indexes in the current DB
Db.printcollectionstats ();
--
MongoDB Common Commands