1. 使用 utf8 字符,默認全部字符爲 utf8
2. 不能含有空格 . / \ "\0" 字符 (c++ 中會將 "\0" 做爲結束標誌,且mongoDB是用 c++ 寫的)
3. 不能超過 64 字節
4. 不要和吸引數據庫重名
全部的變量的命名都是基於 小駝峯式(首字符小寫,後面單詞首字母大寫)mysql
全局變量 db 表明當前正在使用的數據庫c++
未選擇數據庫的時候默認爲 db 爲 test 數據庫sql
mysql 中不選擇數據庫沒法操做數據,shell
mongoDB 則能夠使用默認的 test 數據庫進行數據操做數據庫
use [database]
1. 選擇數據庫,不存在的時候就自動建立
2. 使用此命令建立數據庫不會當即建立,當被插入數據時纔會真正建立json
輸入: use stu 輸出: switched to db stu
show dbs
使用此命令查看剛剛建立的數據庫是沒法查看的,被插入數據後才能夠看到ui
輸入:> show dbs 輸出: admin 0.000GB local 0.000GB
db.dropDatabase()
刪除當前所用的數據庫spa
輸入: > db.dropDatabase() 輸出: { "dropped" : "test", "ok" : 1 }
mongodump -h[host] ip -d[databasename] name -o[path] /usr/abc
1. 路徑選擇不存在的會自動建立文件夾
2. mongo命令,在終端執行,不是在mongo shell 裏面執行rest
輸入: tarena@tedu:~$ mongodump -h 127.0.0.1 -d stu -o dir 輸出: 2019-02-27T14:26:10.240+0800 writing stu.class to 2019-02-27T14:26:10.256+0800 done dumping stu.class (1 document)
輸入: tarena@tedu:~$ ls dir/stu 輸出: class.bson class.metadata.json
mongorestore -h[host:port] -d[database] [file]
mongo命令,在終端執行,不是在mongo shell 裏面執行code
選擇的 數據庫 若是本地不存在也會自動建立
輸入: tarena@tedu:~$ mongorestore -h 127.0.0.1:27017 -d student dir/stu
輸出: 2019-02-27T14:33:39.201+0800 the --db and --collection args should only be used when restoring from a BSON file. Other uses are deprecated and will not exist in the future; use --nsInclude instead 2019-02-27T14:33:39.201+0800 building a list of collections to restore from dir/stu dir 2019-02-27T14:33:39.202+0800 reading metadata for student.class from dir/stu/class.metadata.json 2019-02-27T14:33:39.213+0800 restoring student.class from dir/stu/class.bson 2019-02-27T14:33:39.220+0800 no indexes to restore 2019-02-27T14:33:39.220+0800 finished restoring student.class (1 document) 2019-02-27T14:33:39.220+0800 done
1. mongo命令,在終端執行,不是在mongo shell 裏面執行
2. 輸出參數:
輸入: tarena@tedu:~$ mongostat
輸出: 每秒刷新循環打印一次 insert query update delete getmore command dirty used flushes vsize res qrw arw net_in net_out conn time *0 *0 *0 *0 0 2|0 0.0% 0.0% 0 933M 72.0M 0|0 1|0 159b 46.8k 1 Feb 27 14:41:31.482 *0 *0 *0 *0 0 2|0 0.0% 0.0% 0 933M 72.0M 0|0 1|0 159b 46.8k 1 Feb 27 14:41:32.471 *0 *0 *0 *0 0 2|0 0.0% 0.0% 0 933M 72.0M 0|0 1|0 158b 46.5k 1 Feb 27 14:41:33.467 *0 *0 *0 *0 0 1|0 0.0% 0.0% 0 933M 72.0M 0|0 1|0 157b 46.1k 1 Feb 27 14:41:34.472 *0 *0 *0 *0 0 2|0 0.0% 0.0% 0 933M 72.0M 0|0 1|0 158b 46.5k 1 Feb 27 14:41:35.468 *0 *0 *0 *0 0 2|0 0.0% 0.0% 0 933M 72.0M 0|0 1|0 158b 46.4k 1 Feb 27 14:41:36.466
1. mongo命令,在終端執行,不是在mongo shell 裏面執行
2. 輸出參數:
1. mongo命令,在終端執行,不是在mongo shell 裏面執行
2. 參數說明:
輸入: tarena@tedu:~$ mongotop
輸出: 每秒刷新循環打印一次
ns total read write 2019-02-27T14:49:32+08:00 admin.system.roles 0ms 0ms 0ms admin.system.version 0ms 0ms 0ms local.startup_log 0ms 0ms 0ms local.system.replset 0ms 0ms 0ms stu.class 0ms 0ms 0ms student.class 0ms 0ms 0ms test.class 0ms 0ms 0ms