Skip to content

Mongodb Query Summary.

RDBMS Vs MongoDB

RDBMS MongoDB
Database Database
Table Collection
Tuple/Row Document
column Field
Table Join Embedded Documents
Primary Key Primary Key (Default key _id provided by mongodb itself)

Change Databse
use DATABASE_NAME
Show Database
show dbs
Drop Database
Switch Database then run Code
db.dropDatabase()
Create Collection
db.createCollection(name, options) // options is optional
Ex: db.createCollection(collection)
Show Collection
show collection
Drop Collection
db.collection.drop()
Insert Document in Collection
db.collection.insert(document)
db.collection.save(document)

Select Document from Collection
db.collection.find({Filter Parameter})
.pretty() // For formatted form
.findOne() // Return one Document
******* Filter Syntax ***********
= :{<key>:<value>}
< :{<key>:{$lt:<value>}}
> :{<key>:{$gt:<value>}}
<= :{<key>:{$lte:<value>}}
>= :{<key>:{$gte:<value>}}
<> or != : {<key>:{$ne:<value>}}
ANd : Filter seperated by ,

Leave a Reply

%d bloggers like this: