MongoDb: Difference between revisions
Jump to navigation
Jump to search
Line 36: | Line 36: | ||
<syntaxhighlight lang="JavaScript"> | <syntaxhighlight lang="JavaScript"> | ||
db.changeUserPassword("username:", "newPassWord") | db.changeUserPassword("username:", "newPassWord") | ||
</syntaxhighlight> | |||
* Login | |||
<syntaxhighlight lang="JavaScript"> | |||
mongo -u userName -p passWord --authenticationDatabase admin | |||
or | |||
mongo | |||
use admin | |||
db.auth("userName", "passWord") | |||
</syntaxhighlight> | </syntaxhighlight> | ||
Revision as of 19:59, 6 June 2020
Cheat sheet
- Connect to a mongodb
mongo
- Display dabases
show dbs
- Connect to a database
use database
- List Tables (Collections)
show collections
- Display content of a table
db.collection.find()
- Remove Tables (Collections)
db.collection.drop()
- Remove Database (Collections)
db.dropDatabase()
User Management
- Create Admin user
use admin
db.createUser(
{
user: "userName",
pwd: "passWord",
roles: [ { role: "userAdminAnyDatabase", db: "admin" }, "readWriteAnyDatabase" ]
}
)
- Remove user
use admin
db.dropUser("userName")
- Change user Password
db.changeUserPassword("username:", "newPassWord")
- Login
mongo -u userName -p passWord --authenticationDatabase admin
or
mongo
use admin
db.auth("userName", "passWord")
Database Engine Management
- Stop Database
db.adminCommand( { shutdown: 1} )
Http Interface
Inable Http Interface
add http.enabled: true in /etc/mongod.conf
net: port: 27017 bindIp: 127.0.0.1 http.enabled: true http.RESTInterfaceEnabled: true