Skip to content

Instantly share code, notes, and snippets.

@MikyStar
Created August 7, 2018 08:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MikyStar/55384452cbd8add1d54ab4b7432357ea to your computer and use it in GitHub Desktop.
Save MikyStar/55384452cbd8add1d54ab4b7432357ea to your computer and use it in GitHub Desktop.

Commands

Create the environment

mongod --dbpath [ Path of the folder where I want my DB ]

Launch the shell

mongo --host [ Adress and port where mongod listens on ]

Stop the server

mongod --dbpath [ Path of the database ] --shutdown

Create a database

Once in the MongoDB shell

use [ Name of the database ]
db # Just to check

Manually add datas

Once in the MongoDB shell

db.[table].insert([ JSON format informations ])

Note :

  • "db" is the keyword that we will use, that's why we have to use the use command before, just to select the database
  • The table (which is not really a table because NoSQL) doesn't has to be defined, it will then be added automatically

OR

[name of the variable] = [JSON format informations, that can be an array of course]
db.[table].insert([name of the variable]);

To display what is inside a table

db.[table].find().pretty()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment