Home > AI > Database > MongoDB >

commands

commandsdescription
mongoenters mongo
show databases
show dbs
use testswitch scheme
show tables
df.user.find()get all records in this table

create a database

> use {dbname_to_create}
> db.movie.insert({"name": "jobyme88.com"}) // insert one record
> show dbs // now you can see the created database

In MongoDB default database is test. If you didn’t create any database, then collections will be stored in test database.

drop a database

> use READ__ME_TO_RECOVER_YOUR_DATA
> db.dropDatabase()
{ "dropped" : "READ__ME_TO_RECOVER_YOUR_DATA", "ok" : 1 }

This needs a root role, or you cannot delete the database

> use admin
> db.createUser(
  {
    user: 'admin',
    pwd: 'password',
    roles: [ { role: 'root', db: 'admin' } ]
  }
);
> exit;

change user password

> use products
> db.changeUserPassword("accountUser", passwordPrompt())

Leave a Reply