forked from samirvithlani/nodejs-club3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mongoq.txt
25 lines (18 loc) · 988 Bytes
/
mongoq.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
db.createCollection("user2")
db.user2.insert({name:"abc",age:20,married:false,salary:1000,child:false})
db.user2.insert({name:"aaa",age:30,married:true,salary:2000,child:true})
db.user2.insert({name:"ghi",age:40,married:true,salary:500,child:false})
db.user2.insert({name:"jkl",age:50,married:false,salary:45000,child:false})
find all user who is married and have a child
db.user2.find({married:true,child:true})
findone user having heighest saalry
db.user2.find().sort({salary:-1}).limit(1)
findone user having heighest saalry and married
db.user2.find({married:true}).sort({salary:-1}).limit(1)
provide array of user name and remove matching user name
db.user2.remove({name:{$in:["pqr","aaa"]}})
findone all user having heighest saalry and married and having child
db.user2.find({married:true,child:true}).sort({salary:-1}).limit(1)
find user who is having lowest salary and not married
find oldest user who is not married
db.user2.find({married:false}).sort({age:-1}).limit(1)