Skip to content

Instantly share code, notes, and snippets.

@shreewatsa
Last active July 4, 2023 13:48
Show Gist options
  • Save shreewatsa/37f8f0c11cdac0801ffa9d4c4739e78a to your computer and use it in GitHub Desktop.
Save shreewatsa/37f8f0c11cdac0801ffa9d4c4739e78a to your computer and use it in GitHub Desktop.
Mongodb Cheatsheet

Installing mongosh in Remote Host:

scp ~/Downloads/GoogleChrome/mongosh-1.6.2-linux-x64.tgz remote_host:/home/sysadmin/;
ssh remote_host;
(sysadmin ~)$ tar -zxvf mongosh-1.6.2-linux-x64.tgz;
(sysadmin ~/mongosh1.6/bin)$ cd mongosh*/bin/;¡
(sysadmin ~/mongosh1.6/bin)$ chmod +x ./*;
(sysadmin ~/mongosh1.6/bin)$ sudo cp mongosh* /usr/local/bin/;
(sysadmin ~)$ mongosh;

How to connect to mongo db ?

sudo mongosh --port 27017 -u "db_user" --authenticationDatabase "db_name" -p ;  
> show dbs;
> use db_name;
> show collections;
> db.collection_name.find();

Using 'mongo'

mongo --username admin --password --authenticationDatabase userdb;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment