Skip to content

MongoDB

Install 5

sudo apt install gnupg

wget -qO - https://www.mongodb.org/static/pgp/server-5.0.asc | sudo apt-key add -

echo "deb http://repo.mongodb.org/apt/debian buster/mongodb-org/5.0 main" | sudo tee /etc/apt/sources.list.d/mongodb-org-5.0.list

sudo apt update

#sudo apt install -y mongodb-mongosh=1.0.1
#sudo apt install -y mongodb-mongosh=1.2.2
#sudo apt install -y mongodb-mongosh=1.2.3
sudo apt install -y mongodb-mongosh

Connect to db

mongosh "mongodb://{IP}:27017"

Show dbs

show databases

Use db

use {database-name}

Show collections from db

show collections

Show collection stats

db.{collection-name}.stats()

Get first record from collection

db.{collection-name}.findOne()

Other

db.{collection-name}.find()
db.{collection-name}.find().prettyPrint()