MongoDB uses find to query, the query is to return a subset of the document in a collection, the range of the sub-collection from 0 documents to the entire collection. The first parameter of find determines which documents to return. The empty query document {} matches the entire contents of the collection, and if you do not specify a query document, the default is {}.
There are some restrictions on the use of MongoDB queries, the value of the query document that the database is related to must be constant, that is, the value of other keys in the document cannot be referenced.
The query conditions "$lt", "$lte", "$gt", "$gte", "$ne" are all comparison operators, respectively, corresponding to <, <=, > and >= and "unequal";
"$in" is used to query the value of a key value in a range "$nin" to query for values that are not within a range of key values
"$or" accepts an array that contains all possible conditions as arguments
The $mod modulo operator divides the value of the query by the first given value and returns the result if the remainder equals the second given value
"$not" Query for documents that do not match a specific pattern
A key can have multiple conditions, but a key cannot correspond to more than one update modifier
Null does not just match itself and matches the "nonexistent", and this match returns all documents that are missing the key
If you only want to match a document with a key value of NULL, check whether the value of the key is null, and whether the key value exists through the $exists condition
MongoDB uses a Perl-compatible regular expression (PCRE) library to match regular expressions, and PCRE supports regular expression syntax that can be accepted by MongoDB, and you can now check the syntax Javascrip the shell before using regular expressions
If you need to match an array with more than one element, use "$all"
"$size" can be used to query an array of the specified length
"$slice" returns a sub-collection of arrays that can accept offset values and the number of elements to be returned, unless otherwise declared, returning all keys in the document
There are two ways to query an inline document: Query the document, or query only for its key/value pairs
Querying the entire document requires that the structure match the original data exactly (including the order)
"$elemMatch" groups the qualifying conditions, which are only used when multiple key operations are performed on an inline document, and the result returns all documents that meet the criteria
The "$where" can execute arbitrary JavaScript as part of the query, and the query can do almost anything, but it is not necessary to avoid using the "$where" query, because it is much slower than the regular query speed, Each document is converted from Bson to a JavaScript object and then run through an expression of "$where", which also does not use the index
MongoDB Learning Note 02