mongodb基础命令大集合
Basic Commands
User management commands:
db.createUser()
db.dropUser()
Collection management commands:
db.<collection>.renameCollection()
db.<collection>.createIndex()
db.<collection>.drop()
Database management commands:
db.dropDatabase()
db.createCollection()
Database status command:
db.serverStatus()
Creating index with Database Command:
db.runCommand(
{ "createIndexes": <collection> },
{ "indexes": [
{
"key": { "product": 1 }
},
{ "name": "name_index" }
]
}
)
Creating index with Shell Helper:
db.<collection>.createIndex(
{ "product": 1 },
{ "name": "name_index" }
)
Introspect a Shell Helper:
db.<collection>.createIndex
Logging Basics
Get the logging components:
mongo admin --host 192.168.103.100:27000 -u m103-admin -p m103-pass --eval '
db.getLogComponents()
'
Change the logging level:
mongo admin --host 192.168.103.100:27000 -u m103-admin -p m103-pass --eval '
db.setLogLevel(0, "index")
'
Tail the log file:
tail -f /data/db/mongod