Mongodb Study Notes 03 -- query expression
Mongodb Study Notes 03-query expression
Not equal to, greater than, less
! =: Db. stu. find ({name: {$ ne: 'billvsme '}) name is not 'billvsme'>: db. stu. find ({age: {$ gt: 18}) older than 18 <: db. stu. find ({age: {$ lt: 18}) younger than 18 >:$ gte <=: $ lte
In/not in/all
$ In: db. goods. find (stu_id: {$ in: [93001,93002, 93003]}) Student ID 93001, 93002, or 93003 $ nin: not in $ all: the specified content has db. stu. find ({like: {$ all: ['football', 'bucketball ']}) students who like basketball and football
Or/and/not/nor
$ Or: or $ and: and the example db. stu. find ({$ and: [{age: {$ gt: 18 },{ age: {$ lt: 22}]}) between 18 and 22: $ not: not $ nor: If none of the conditions you write are true, this line is returned.
Exists/mod/type
$ Exists: Example db. find ({body :{$ exists: 1}) columns with the body field $ mod: satisfy the remainder. Example db. stu. find ({stu_id: {$ mod: [5, 0]}) to get the student ID is a multiple of 5 $ type: satisfies the type example db. stu. find ({age: {$ type: 2}) the age segment type is a string column. 2: indicates the type code specific see http://docs.mongodb.org/manual/reference/operator/query/type/#op._S_type
Where/regex
(Use it with caution, because if you use it, mongo needs to convert binary bson into json and then perform the operation, which is inefficient)
$ Where: If the js expression is true, it is true. Example db. stu. find ({$ where: 'This. age> 18'}) age greater than 18 $ regex: the regular expression is true. Example db. stu. find ({name: {$ regex: '^ bill'}) name starting with bill