Mongodb quick reference
mongo -u admin -p 123 — authenticationDatabase admin
Create DB
> use nskdb
To create db use need to insert data in atleast one document
db.movie.insert({“name”:”tutorials point”})
NOTE:
In MongoDB default database is test. If you didn’t create any database,
then collections will be stored in test database.
Drop DB
select db with use command
> use nskdb
> db.dropDatabase()
Create Collection
syntax is:-
db.createCollection(name, options)
options can be :-
— capped, autoIndexId, size, max
Get Weave Bytes’s stories in your inbox
Join Medium for free to get updates from this writer.
> db.createCollection(“mycollection”)
> db.createCollection(“mycol”, { capped : true, autoIndexId : true, size :
6142800, max : 10000 } )
> db.createCollection(“user”, { autoIndexId : true } )
> show collections
Drop Collection
> db.mycollection.drop()
The insert() Method
db.mycol.insert({
title: ‘MongoDB Overview’,
likes: 100
})
BULK WRITE
To insert multiple documents in a single query, you can pass an array of documents in insert() command.
db.mycol.insert([{
title: ‘Python Overview’,
likes: 200
},
{
title: ‘Nodejs Overview’,
likes: 70
},
])
The find() Method
db.COLLECTION_NAME.find()
> db.mycol.find()
> db.mycol.find().pretty()
> db.mycol.find({likes: 100}).pretty()







