MongoDb: Difference between revisions
Jump to navigation
Jump to search
Line 2: | Line 2: | ||
* Connect to a mongodb | * Connect to a mongodb | ||
<pre>mongo</pre> | <pre>mongo</pre> | ||
* Display dabases | * Display dabases | ||
<pre>show dbs</pre> | <pre>show dbs</pre> | ||
* Connect to a database | * Connect to a database | ||
<pre>use database</pre> | <pre>use database</pre> | ||
* List Tables (Collections) | * List Tables (Collections) | ||
<pre>show collections</pre> | <pre>show collections</pre> | ||
* Create Collection | |||
<syntaxhighlight lang="JavaScript"> | |||
use formation | |||
db.cours.insert({"titre":"MongoDB 101"}) | |||
</syntaxhighlight> | |||
* Display content of a table | * Display content of a table | ||
<pre>db.collection.find()</pre> | <pre>db.collection.find()</pre> | ||
* Remove Tables (Collections) | * Remove Tables (Collections) | ||
<pre>db.collection.drop()</pre> | <pre>db.collection.drop()</pre> | ||
* Remove Database (Collections) | * Remove Database (Collections) | ||
<pre>db.dropDatabase()</pre> | <pre>db.dropDatabase()</pre> | ||
=== User Management === | === User Management === | ||
* Create Admin user | * Create Admin user |
Revision as of 03:57, 7 June 2020
Cheat sheet
- Connect to a mongodb
mongo
- Display dabases
show dbs
- Connect to a database
use database
- List Tables (Collections)
show collections
- Create Collection
use formation
db.cours.insert({"titre":"MongoDB 101"})
- 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 admin -u 'userName' -p 'passWord'
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