How to realize pagination display in MongoDB
MongoDB how to achieve paging display, many novices are not very clear about this, in order to help you solve this problem, the following editor will explain in detail for you, people with this need can come to learn, I hope you can gain something.
The data paging display in MongoDB is also an operation function that meets the requirements of big data:
Skip (n): indicates how many rows of data are crossed
Limit (n): limit on the number of rows to be fetched.
Example: pagination display (first page, skip (0), limit (5))
> db.emp.find () .skip (0) .limit (5) .sort ({"age":-1}) .pretty ()
{
"_ id": ObjectId ("599108423268c8e84253be2c")
"name": "Zheng Qi"
"sex": "female"
"age": 50
"sal": 4700
"loc": "Chengdu"
}
{
"_ id": ObjectId ("599108423268c8e84253be28")
"name": "Sun San"
"sex": "male"
"age": 40
"sal": 2000
"loc": "Shenzhen"
}
{
"_ id": ObjectId ("599148bf0184ff511bf02b95")
"name": "Lin E"
"sex": "male"
"age": 40
"sal": 8000
"loc": "Beijing"
"course": [
"Chinese"
"politics"
]
"parents": [
{
"name": "Father Lin E"
"age": 70
"job": "worker
}
{
"name": "Mother Lin E"
"age": 68
"job": "Director"
}
]
}
{
"_ id": ObjectId ("599108433268c8e84253be2d")
"name": "bastards"
"sex": "male"
"age": 35
"sal": 8000
"loc": "Beijing"
}
{
"_ id": ObjectId ("599129a00184ff511bf02b87")
"name": "Liu A"
"sex": "male"
"age": 35
"sal": 8000
"loc": "Beijing"
"course": [
"Chinese"
"Mathematics"
"English"
"Music"
"politics"
]
}
Example: pagination display (page 2, skip (5), limit (5))
> db.emp.find () .skip (5) .limit (5) .sort ({"age":-1}) .pretty ()
{
"_ id": ObjectId ("599129a00184ff511bf02b88")
"name": "Liu B"
"sex": "male"
"age": 35
"sal": 8000
"loc": "Beijing"
"course": [
"Chinese"
"Mathematics"
]
}
{
"_ id": ObjectId ("599129a00184ff511bf02b89")
"name": "Liu C"
"sex": "male"
"age": 35
"sal": 8000
"loc": "Beijing"
"course": [
"Chinese"
"Mathematics"
"English"
]
}
{
"_ id": ObjectId ("599129a00184ff511bf02b8a")
"name": "Liu D"
"sex": "male"
"age": 35
"sal": 8000
"loc": "Beijing"
"course": [
"Chinese"
"Mathematics"
"politics"
]
}
{
"_ id": ObjectId ("599129a20184ff511bf02b8b")
"name": "Liu E"
"sex": "male"
"age": 35
"sal": 8000
"loc": "Beijing"
"course": [
"Chinese"
"politics"
]
}
{
"_ id": ObjectId ("599148bd0184ff511bf02b93")
"name": "Lin C"
"sex": "male"
"age": 35
"sal": 8000
"loc": "Beijing"
"course": [
"Chinese"
"Mathematics"
"English"
]
"parents": [
{
"name": "Lin C's Father"
"age": 60
"job": "worker
}
{
"name": "Lin C Mother"
"age": 59
"job": "staff
}
]
}
Is it helpful for you to read the above content? If you want to know more about the relevant knowledge or read more related articles, please follow the industry information channel, thank you for your support.