BASIC MONGODB COMMANDS

basic bottles of mongoDB commands

Hi all, this is just my personal dev notes that I keep here so I can get a reminder from time to time. I’ve recently started to play around with Mongdb with great success using the MEAN stack approach, so I wont be going through the setting up but just some basic commands to get you going and started.

RUN COMMAND

mongo

CREATE A NEW TABLE COMMAND

use DBNAME

Once successful you will see the command line mention that you have “switched to db DBNAME”

SHOW DATABASE LIST COMMAND

show dbs

The terminal will list the available databases.

INSERT DOCUMENT INTO DATABASE

db.DBNAME.insert({
         firstName: "Tony", 
         lastName: "Marques",
         avatar: "01"
})

// result should show 
WriteResult({ "inserted" : 1 })

Hope this helps you quickly along. I am using MongoDB Compass Version 1.29.5 and node v14.18.0