For more information about data comparison and other instructions can be found in official documents
$eq | = |
---|---|
$gt | > |
$gte | >= |
$lt | < |
$ lte | <= |
$ does | != |
// 18. Num query document numbers in the 500
db.numbers.find({num:500})
19 // Query numbers in num is greater than 5000 documents
db.numbers.find({num:{$gt:500}});
db.numbers.find({num:{$eq:500}});
// 20. Num query numbers in less than 30 documents
db.numbers.find({num:{$lt:30}});
21 // Query numbers in num is greater than 40 documents less than 50
db.numbers.find({num:{$gt:40 , $lt:50}});
22 // Query numbers in num is greater than the document 19996
db.numbers.find({num:{$gt:19996}});
// 23 View the first 10 numbers in the collection of data
db.numbers.find({num:{$lte:10}});//具有特殊性,数据是有序的
// limit () Set the upper limit of the display data
db.numbers.find().limit(10);
// in the development, we will not execute the query without conditions
db.numbers.find();
// 24. See the article in a set of numbers 11 through 20 of data
/ *
page 10 per
1-10 0
11-20 10
21-30 20 is
. . .
skip((页码-1) * 每页显示的条数).limit(每页显示的条数);
skip()用于跳过指定数量的数据
MongoDB会自动调整skip和limit的位置
db.numbers.find().skip(10).limit(10);
// 25 View Article 21-30 numbers in the collection of data
db.numbers.find().skip(20).limit(10);
db.numbers.find().limit(10).skip(10);