MongoDB Learning Note 03– query expression
Not equal to, greater than, less than
- ! =: 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}}) older than 18
- >=: $GTE
- <=: $LTE
In/not In/all
- $in:db.goods.find (stu_id:{$in:[93001,93002,93003]}) study number 93001 or 93002 or 93003
- $Nin:not in
- $All: The specified content has db.stu.find ({like:{$all: [' Football ', ' Basketball '}}) students who like basketball and football
Or/and/not/nor
- $or: or
- $and: and Example Db.stu.find ({$and:[{age:{$gt:18}},{age:{$Lt:22}}}) age between 18 and 22
- $not: non-
- $Nor: If you write a condition that is not true, then return this article
Exists/mod/type
- $exists: Example Db.find ({body:{$exists: 1}}) column with body field
- $mod: satisfies the remainder, example db.stu.find ({stu_id:{$mod:[5,0]}) takes a number that is a multiple of 5
- $Type: Satisfies the type example Db.stu.find ({age:{$Type:2}}) The age segment type is a column of string. 2: The expression type code specifically see http://docs.mongodb.org/manual/reference/operator/query/type/#op. _s_type
Where/regex
(Use caution, because if used, MONGO to convert binary Bson into JSON and then operate, inefficient)
- The $where:js expression is true. Example Db.stu.find ({$where: ' this.age>18 '}) older than 18
- $Regex: The regular expression is true. Example Db.stu.find ({name:{$regex: ' ^bill '}}) the name begins with Bill
MongoDB Learning Note 03--Query expression