mongodb database operator

one. Conditional operator:

   (>) greater than - $gt

   (<) less than - $lt

   (>=) greater than or equal to - $gte

   (<= ) less than or equal to - $lte

example:

>use date
switched to db date
>db.users.insert([{'name':'Ada','age':20},{'name':'Aer','age':25},{'name':'Asan ','age':30}])
>db.users.find({"age" : {$gt : 22}})
[{'name':'Aer','age':25},{'name':'Asan','age':30}]

  This is a query about the greater than operator. The rest of the operators are similar.

 

two. $all matches all values.

example:

>db.users.insert([{'name':'阿大','age':20,'kk':[10,20,30]},
{'name':'A'er','age':25,'kk':[10,22,30]},
{'name':'Asan','age':30,'kk':[10,22,32]
}])
>db.users.find({"kk" : {$all:[10,22]}})
[{'name':'A'er','age':25,'kk':[10,22,30]},
{'name':'Asan','age':30,'kk':[10,22,32]}
]

 The value in the query key kk contains all the information of [10.22].

 

3. The value contained in the $in query

example:

>db.users.insert([{'name':'阿大','age':20,'kk':[10,20,30]},
{'name':'A'er','age':25,'kk':[10,22,30]},
{'name':'Asan','age':30,'kk':[10,22,32]
}])
>db.users.find({"age" : {$in:[24,31]}})
[{'name':'A'er','age':25,'kk':[10,22,30]},
{'name':'Asan','age':30,'kk':[10,22,32]}
]

 The value of the query key age 24=<age<=31.

 

Four. $exists determines whether the field exists (true exists, false does not exist)

example:

>db.users.find({'age':{$exists:false)

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326681570&siteId=291194637