doc

# 创建一个用户管理员
mongo 
use admin
db.createUser(
    {
        user: "myUserAdmin",
        pwd: passwordPrompt, // 或者输入明文密码
        roles: [ { role: "userAdminAnyDatabase", db: "admin" }, "readWriteAnyDatabase" ]
    }
)
​
​
mongo -u root # 登录mongo
show dbs
use db #切换数据库
db.createCollection("runoob") #创建集合
show collections
db.col.createIndex({keyword:1}, {unique: true})
db.col.remove() # 删除集合所有数据
​
### mongodump 备份数据
(mongodump -u root -p globalso8837840 -d google_search -c tags_kwd_new_result --authenticationDatabase admin >> mongo.log 2>&1 &)
​
### 恢复数据
​

备份与恢复

备份与恢复

### mongodump 备份数据 mongodump -h dbhost -d dbname -o dbdirectory
nohup mongodump -u root -p globalso8837840 -d google_search -c tags_kwd_new_result --authenticationDatabase admin -o mongo_backup/ > mongo.log 2>&1 &
### 恢复数据 mongorestore -h <hostname><:port> -d dbname <path>
mongorestore -h 23.228.125.2:27017 -u root -p globalso8837840 -d globalso_monitor mongo_backup/globalso_monitor