1, start the service
Using Parameters
--dbpath specifying the data file path
--logpath Specifying error log files
--logappend Error Log Append method
--BIND_IP Listening IP Address
--port Listening Port
-F Start with parameter file
--folk Running in daemon mode
--syndelay the time of the system to flush the disk synchronously, the unit is wonderful
./mongod--dbpath=/data--logpath=/data/mongo.log--folk--bind_ip=192.168.234.154--port 999
If you start with a parameter file, you can write your own parameter file
Vim mongo.conf
Dbpath=/data
Logpath=/data/mongo.log
for (Var i=1;i<10;i++) db.test.save (' C ': i);
Db.test.find ();
./mongod-f mongo.conf--folk
2, some management tools
Bsondump: Dumps files in Bson format to JSON-formatted data
Mongodump/mongoimport Data Export Import Tool
Mongofiles:gridfs management tool to enable binary file access
MONGOs: Shard Routing, if the sharding feature is used, the application connects MONGOs instead of Mongod
Mongosniff: Similar to Tcpdump tool, fetch only MONGDB data
Mongostat: Real-time monitoring tool
View data space size
Db.userInfo.dataSize ();
> Db.pincer.dataSize ()
548
6, get the aggregate aggregate size
Db.userInfo.totalSize ();
7, aggregate storage space size
Db.userInfo.storageSize ();
8. Shard Version Information
Db.userInfo.getShardVersion ()
9. Clustered Collection Rename
Db.userInfo.renameCollection ("users");
Rename UserInfo to users
10. Delete the current aggregation collection
Db.userInfo.drop ();
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 ();
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");
Verify Login:
MONGO--host=ip--port=num-uuser-ppassword dbname
1, the error message before the query
Db.getpreverror ();
2. Clear the Error Record
Db.reseterror ();
3. Clustered Collection Rename
Db.userInfo.renameCollection ("users");
List the actions that are being performed
Db.currentop (dbname)
Kill the operation that is being carried out
Db.killop (Opid)
Create a Collection
1, create a collection that is 100 000 bytes
Db.createcollection ("mycollection", {capped:true,size:100000})
2, create a collection with a size of 100000 bytes and a maximum document count of 100
Db.createcollection ("mycollection", {capped:true,size:100000max:100})
Force buffer data to be flushed to disk
Db.runcommand ({"Fsync": 1, "Lock": 1})
Online Backup and Recovery
mongodump-d Database-o Backupdir
mongorestore-d Database--drop Backupdir
MONGO Master
Master
Mongod--bind_ip=192.168.0.1--port=999--dbpath=/test--logpath=/test/mongo.log--logappend--master
Slave
Mongod--bind_ip=192.168.0.2--port=998--dbpath=/test--logpath=/test/mongo.log--logappend--slave--source 192.168.0.1:999
--only Copy only the specified database
--slavedelay from node delay, unit is seconds
--autoersync automatic resynchronization If the slave node is not synchronized with the primary node
--oplogsize primary node Oplog size, in units of M
This article from "Pincer" blog, reproduced please contact the author!
MongoDB Common Basic Management commands