ip192
ip192

Reputation: 149

Can't get data by using aggregate in mongodb

Server mongo version is 3.4.4. Connected by Studio 3T. When I query like this in IntelliShell

db.orders.aggregate([
    { $limit: 10 },
    { $skip: 10 }
])

I get nothing returned.
However, when I switch the $limit and $skip,

db.orders.aggregate([
    { $skip: 10 },
    { $limit: 10 }
])

It works fine.

Upvotes: 0

Views: 199

Answers (1)

ip192
ip192

Reputation: 149

This is my understanding: The $limit: 10 means 'I want ten result', and the $skip means 'I don't need the first tens'.
So, I get 0 results by the first query, get 10-20 results by the second query.

Upvotes: 1

Related Questions