This article is updated on 2022-01-22, Use MongoDB 4.4.5.
bsondump
BSON View tools .
bsondump BSONFILENAME
mongo
JavaScript shell.
mongo [OPTION] [DB_NAME|HOST[:PORT][/DB_NAME]|MONGODB_URI] [JS_FILENAME[ ...]]
OPTION for :
- --nodb: start-up shell Do not connect to any mongod.
- --norc: start-up shell Do not load .mongorc.js. It will load by default .
- --password|-p [PASSWORD]: Specified password . If not specified PASSWORD, Prompt for password in the interactive interface .
- --quiet: Do not print the prompt message after successful connection .
- --username|-u USERNAME: Specify user name .
If not specified DB_NAME or HOST[:PORT][/DB_NAME or MONGODB_URI, Default connection to localhost:27017/test.
MONGODB_URI The format is :mongodb://[USERNAME[:PASSWORD]@]HOST[:PORT][,...,HOST1[:PORT1]][/[DB_NAME]][?NAME=VALUE[&...&NAME1=VALUE1]]
.NAME=VALUE for :
- replicaSet=REPLSET_NAME: Replica set name . If this parameter is used , You can specify any ( You don't need all )HOST[:PORT], The primary node connection will be automatically selected .
As specified JS_FILENAME, Then execute the script file in turn and exit ( The relative path depends on shell Running directory ). otherwise , Use... Interactively shell.
mongod
MongoDB The server .
mongod [OPTION]
mongod --replSet REPLSET_NAME
mongod --repair [--repairpath DST_DIR] [--dbpath DIR]
OPTION for :
- -v: The level of logging . If this option is not used, it is the lowest value 0;-vvvvv Is the highest value 5( Record almost all operations , Including the content of each request processing ).
- --auth: Enable Authentication .
- --bind_ip: Monitoring IP.
- --dbpath DIR: Data directory . The default is /data/db(Windows For the current drive ).
- --config|-f FILENAME: The configuration file . The options specified on the command line can override the values in the configuration file .
- --configsvr: Start as a configuration server . The default port is 27019, The default data directory is /data/configdb.
- --fork: Create a child process running in the background . It needs to be used at the same time --logpath.
- --directoryperdb: Each database is stored in a separate directory .
- --help: view help .
- --journalCommitInterval MICROSECONDS: The time interval between journal system submission . The unit is millisecond , The minimum is 2, The maximum is 500.
- --logappend: Write the log file by appending . It needs to be used at the same time --logpath.
- --logpath FILENAME: Log output file . If not specified, output to standard output .
- --noprealloc: Prohibit pre allocation of data files .
- --noscripting: Prohibition of execution JavaScript Script . Be careful , some shell Auxiliary functions depend on JavaScript Script .
- --nounixsocket: No monitoring UNIX Socket .
- --port PORT: Listening port . The default is 27017.
- --profile LEVEL: Set the system analyzer level .0 To turn off the system analyzer ,1 Slow query for record only ,2 To record all operations .
- --quiet: No log output .
- --repair: Repair data . Will not listen on port , But the log will be output .
- --repairpath DST_DIR: Specify the destination directory for copying files when repairing .
- --replSet REPLSET_NAME: Specify the replica set name , Start as replica set node . Do not use this option , Start in stand-alone mode .
- --shardsvr: Start as a fragment . The default port is 27018,
- --slowms MICROSECONDS: Set the slow query threshold of the system analyzer . The unit is millisecond .
- --syncdelay SECONDS: The interval between flushing dirty pages to disk . The unit is in seconds .
The format of the configuration file is as follows :
#
The following content is ignored as a comment .- The syntax of the specified parameter is
OPTION = VALUE
.OPTION Remove--
, If the command line parameter is a switch option that does not need to specify a value VALUE Set totrue
.
mongodump
Data backup tools . During the backup process, write operations will continue .
mongodump [OPTION]
OPTION for :
- --help: view help .
- --oplog: At the same time, dump the operation logs in the backup process oplog, To get a snapshot of the backup point in time . Such as backup replica set , This option is required .
- --out|-o DUMPDIR: The output directory . The default is dump. The output directory contains several directories named database , Each directory contains several .bson Data files and .metadata.json Metadata file .
- --port PORT: The port of the server .
- --version: View version .
Such as connecting to a replica set , Then a backup node will be automatically selected to perform the backup operation .
If connected to mongos, All partitions will be backed up .
mongofiles
GridFS Tools .
mongofiles [OPTION] COMMAND [ARG]
OPTION for :
- --db|-d DBNAME: Specify database .
- --help: view help .
- --local|-l LOCALFILENAME: Local filename , Used only for
put
andget
Sons command .
COMMAND [ARG] for (FILENAME Can be a file path ):
- delete FILENAME: from GridFS Delete files in .
- get FILENAME: take GridFS Download the files in to the file system .
- list [PREFIX]: List GridFS Documents in . Find by prefix matching . If no prefix is specified , Then list all documents .
- put FILENAME: Upload the files in the file system to GridFS.
- search SUBSTRING: stay GridFS Searching for files in . Search substring .
mongorestore
Data recovery tools .
mongorestore [OPTION] [DUMPDIR|BSONFILENAME]
OPTION for :
- --collection|-c COLLECTIONNAME: Restore only the specified set .
- --db|-d DBNAME: Restore only the specified database .
- --dir DUMPDIR: Backup data directory to be restored . The default is dump.
- --drop: Perform data replacement , Delete the collection before restoring it .
- --oplogReplay: Replay operation log oplog, To get a snapshot of the backup point in time .
- --port PORT: The port of the server .
- --version: View version .
If connected to mongos, All partitions will be restored .
mongos
Patch routing .
mongos [OPTION]
mongos --configdb CONFIG
OPTION for :
- --configdb CONFIG: Specify the configuration server , The format is REPLSET_NAME/HSOT_PORT<,...,HSOT_PORT>.
- --maxConns N: Specify the maximum number of connections .
- --nosplit: Turn off the splitting of blocks .
- --port PORT: Specify listening port . The default is 27017.
mongostat
Status statistics tool . Output once every other period , Count the information since the last output . Can connect to replica sets and sharding clusters .
mongostat [OPTION] [INTERVAL_SECONDS]
OPTION for :
- --discover: Find all nodes of replica set or partitioned cluster , A line of information is also output for each node .
The output contains the following fields :
- host: The host address .
- insert: Number of inserts .
- query: Number of queries .
- update: Number of updates .
- delete: The number of deletions .
- getmore: The number of times to get more data when querying the cursor .
- command: The number of times the command was executed .
- dirty:
- used:
- flushes: The number of times data is refreshed to disk .
- mapped: Mapped memory size . Usually approximately equal to the size of the data directory .
- vsize: The size of virtual memory in use . Usually the data directory 2 times ( Once for mapping files , Once used in the diary system ).
- res: The amount of memory in use . Generally, it should be as close as possible to the memory size of the machine .
- faults:
- qrw: The queue size of read and write operations . That is, the number of blocked read and write operations . Read and write to “|” Separate .
- arw: Number of active clients reading and writing . That is, the number of clients reading and writing . Read and write to “|” Separate .
- net_in: The number of bytes transmitted through the network . It doesn't have to be equal to the statistics of the operating system .
- net_out: The number of bytes transmitted through the network . It doesn't have to be equal to the statistics of the operating system .
- conn: Number of open connections . Including input and output connections .
- set: Replica set name .
- repl: Node state of replica set .
- time: Statistical time point .
mongotop
Collect real-time monitoring tools . Output once every other period .
mongotop [OPTION] [INTERVAL_SECONDS]
OPTION for :
- --locks: Check the lock status of each database .