Installation des paquets ubuntu

apt install mongodb-clients mongodb-server mongo-tools

Lancement du client

mongo

Listes les bases de données :

show dbs

Création d'une base / Connexion a une base :

use movies

Listes les collections :

show collections

Insertion d'un document dans une collection :

db.movie.insert((name:"Batman : Under the Red Hood"))

Recherche d'un document :

db.movie.find()
db.movie.find().pretty()
db.movie.find({name:"Batman : Under the Red Hood})

Mettre à jour un document :

db.movie.update({name:"Batman : Under the Red Hood"},{$set:{editor:"DC Comics"}})
db.movie.update({name:"Batman : Under the Red Hood"},{$unset:{editor:""}})

Supprimer un document :

db.movie.remove({name:"Batman : Under the Red Hood"})

Vider la collection :

db.movie.remove({})

Détruire la collection :

db.movie.drop()

Détruire la base courante (celle sélectionnée avec use):

db.dropDatabase()