Web
Analytics
mongoDB basic queries Part-1 | Angular | ASP.NET Tutorials

For Consultation : +91 9887575540

Stay Connected :

mongoDB basic queries

Go to bin folder of mongo
To Start Mongo server : click on mongod
To Start Console for working ; click on mongo

Start Writing queries
Note : Mongo queries are case sensitive

To Show All databases: show dbs
To use database: use [databasename]
To create Collection into database: db.createCollection(‘friends’)
To Insert record : db.friends.insert({name: “Ganesha”, fname: “Shiva”})
to show all collections: db.friends.find()
Note: We may able to alter number of fields in any collection
To show specific values(like where clause in SQL): db.friends.find({name: “ganesha2”})
Greter than : db.friends.find({age: {$gt : 20}}) –> It will find those records whose age is greated than 20
Get a Single Field: db.friends.find({},{age: 1, _id:0})
Get a Single Field with sorted: db.friends.find({},{age: 1, _id:0}).sort({age:1})
Get a Single Field with sorted(Desc): db.friends.find({},{age: 1, _id:0}).sort({age:-1})
get Limited Rows : db.friends.find().limit(2)