1. Basic commands
1.Help view command prompt
help
db.help();
db.yourColl.help();
db.youColl.find().help();
rs.help();
2. Switch / create database
use yourDB; when a table is created, the current database is automatically created
3. Query all databases
show dbs;
4. Delete the current database
db.dropDatabase();
5. Clone the database from the specified host
db.cloneDatabase ("127.0.0.1"); clone the data of the database on the specified machine to the current database
6. Copy the specified database data from the specified machine to a database
db.copyDatabase ("mydb", "temp", "127.0.0.1"); copy the data of the local mydb to the temp database
7. Repair the current database
db.repairDatabase();
8. View the currently used database
db.getName();
db; The db and getName methods have the same effect, both can query the currently used database
9. Display the current db status
db.stats();
10. Current db version
db.version();
11. Check the link machine address of the current db
db.getMongo();
2. Collection
1. Create an aggregated collection (table)
db.createCollection(“collName”, {size: 20, capped: 5, max: 100});
2. Obtain the specified name of the aggregation set (table)
db.getCollection(“account”);
3. Get all the aggregate collections of the current db
db.getCollectionNames();
4. Display the status of all clustered indexes in the current db
db.printCollectionStats();
5. Delete the data in the aggregate
db.collection.remove({});
3. 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. Display all current users
show users;
4. Delete user
db.removeUser(“userName”);
4. Other
1. Check the previous error message
db.getPrevError ();
2. Clear error records
db.resetError();
5. View the basic information of the collection
1. View help
db.yourColl.help();
2. Query the number of data items in the current collection
db.yourColl.count();
3. View the size of the data space
db.userInfo.dataSize();
4. Get the db where the current aggregate collection is located
db.userInfo.getDB();
5. Get the current state of aggregation
db.userInfo.stats();
6. Get the total size of the aggregate set
db.userInfo.totalSize();
7, the size of the storage space of the aggregate collection
db.userInfo.storageSize();
8. Shard version information
db.userInfo.getShardVersion()
9. Rename the aggregate collection
db.userInfo.renameCollection ("users"); rename userInfo to users
10. Delete the current aggregate collection
db.userInfo.drop();