1, Db.table.find () query all information Db.table.findOne () query the first information
2, Db.table.find ({condition},{to display column}) db.table.find ({},{_id:0,name:0}) query is not realistic _id and name others are displayed
3. Query conditions {age:{$gte: $lte: +}} ==>age>=22 and age<=30
$lt (<), $lte (<=), $GT (>), $gte (>=), $ne (! =)----Db.table.find ({age:{$gte: $, $lte: 30}},{_id:0})
$in and $nin can only function in the array range Db.table.find ({name:{$in: [' 123 ', ' 456 ']}},{_id:0});
$or operation with $or:[{where},{where:{}}] Db.table.find ({$or: [{age:{$gte: 20}},{id:{$gte: 100}}]},{_id:0})
$not fetch operation, can function in any expression, Db.table.find ({name:{$not:/li/}},{_id:0});
You can also process query Db.table.find ({name:/mongodb/},{_id:0}) in a regular
$all Array queries must all contain Db.table.find ({array:{$all: [' MongoDB ', ' JS ', ' java ']}},{_id:0} ') array must contain all Mongod JS Java to come out
Query db.table.find ({' array.1 ': ' MongoDB '},{_id:0}) based on the array subscript query the first element in array arrays is a collection of MongoDB
$size Query Db.table.find ({array:{$size: 3}},{_id:0}) based on the length of the array cannot be manipulated with other comparer operations such as > or <
However, you can add a key to the file: Record the size of the array. Add one element at a time or reduce one element to add 1 and minus 1 for the added key.
$slice Array-scoped query, showing only a few arrays in the array db.table.find ({name: ' H '},{array:{$slice: [1,3]},_id:0}) shows only the data in the middle of the array labeled 1-3
displays the last element of the array {$slice: -1}db.table.find ({name: ' H '},{array:{$slice: -1},_id:0})
when there are multiple objects in the array, query array:[{name:2},{name:1}] can use the object. The way Db.table.find ({' Array.name ': ' 1 '},{_id:0})
queries $elemMatch arrays typically use this query, Db.table.find ({array:{$elemMatch: {obj: ' 1 ', S: ' A ' }}})
4, $where complex query conditions, performance is not very high. The query can have the root function db.table.find ({"$where": Function () {}})
5. Limit () query the file for the first few data db.table.find ({},{_id:0}). Limit (2)
6. Skip () jumps through a few data queries Db.table.find ({},{_id:0}). Limit (2). Skip (5) from 5th, check 2 and limit can be paged
7, sort () sorted 1 Positive order-1 reverse db.table.find ({},{_id:0}). Sort ({age:-1}) document in MongoDB key is irregular
MongoDB key can store different types of data, and the sort will have priority
minimum > Null > Number > String > Object/document > Array > Array > binary > Object id>boolean> date > Timestamp > Regular > Max
8. Skip () Paging performance issues You can add a date to the document, Db.table.find ({date:{$ge: Date value}},{_id:0}). Limit
9. Cursor Traversal data
cursor Destroy condition 1, default more than 10 minutes does not destroy 2, cursor iteration completion 3, the client sends information to destroy
var data=db.table.find ();
While (Data.hasnext ()) {
var o = Data.next ();
print (o);
}
10. Query Snapshot Db.table.find ({$query: {name: ' One '}, $snapshot: true})
11. Advanced Inquiry
$query,
$orderby,
$MAXSCN, maximum number of scanned documents
$min, query start
$max, end of query
$hint, use that index
$explain: Boolean statistics
$snapshot: Boolean consistent snapshot
MONGDB Query Operations