Mongodb Study Notes 03. mongodb Study Notes
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 contains 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: non
- $ Nor: If none of the conditions you write are true, this one is returned.
Exists/mod/type
- $ Exists: In the example db. find ({body :{$ exists: 1}), the column of the body field exists.
- $ Mod: returns the remainder. For example, db. stu. find ({stu_id: {$ mod: [5, 0]}) is a multiple of 5.
- $ Type: A string column is the age segment type that meets the type example db. stu. find ({age: {$ type: 2. 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'}) is older than 18
- $ Regex: the regular expression is true if it is true. Example db. stu. find ({name: {$ regex: '^ bill'}) name starting with bill