How to Run database commands in MongoDB

After made a connection to the database as using command mongo

Now you will run mongo command in terminal . Use show dbs to view databases in mongo.

you can use command use db to create or switch to the database already / to create new .

use shop // default database with metadata


db.products.insertOne({name:"Laptop", price:7999})

You will get the acknowledgment after insertion of data with the inserted id as below for that record.

YOu  will get the result using below command find()

use in a readable format you can format it using pretty()


insert as data in whichever format you want as it is schema-less

now view all your data using find command 

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *

You have successfully subscribed to the newsletter

There was an error while trying to send your request. Please try again.

codeforbetter will use the information you provide on this form to be in touch with you and to provide updates and marketing.