MongoDB operations-1

 Follow the below link to install and configure MongoDB community server & mongo shell

https://drive.google.com/file/d/1lrBr3ftngnkdXc2Oidm31iVUnEUJJ_ci/view?usp=sharing



Practice the following DB CRUD operations.

1. Create user collection and insert 5 user documents in it.

{

name : “ xxxxxx” ,

age : xx ,

salary : xxxxxx,

skills : [ xxxx , xxxx , xxxx ] ,

address : { 

city:”xxx”,

pincode:xxxxxx

    }

}





2.  Find all users

db.users.find()





3. Find user with name “Ravi”

db.users.find({name:”ravi”})





4. Find users from city Hyderabad

db.users.find({"address.city":"hyderabad"})





6. Find users whose salary is greater than 30000

db.users.find({salary:{$gt:30000}})





5 . Find users whose age between 20 and 25

db.users.find({$and :[{age:{$gt:20}},{age:{$lt:25}}]})





6. Find names of all users

db.users.find({},{name:1,_id:0})





7. Find the users  with ”angular” as  a skill

db.users.find({skills:'angular'})





8. Find users with skills as “angular” and “css”

db.users.find( { skills : { $all :["angular","css"]}})





9. Find users who have only two skills

db.users.find( { skills : { $size : 2 }} )







Comments

Popular posts from this blog