Aggregation Framework - Order of $limit and $skip is important

2,342 views
Skip to first unread message

mongo-php

unread,
Apr 5, 2012, 9:03:16 AM4/5/12
to mongod...@googlegroups.com
Hey Group,

why is there a difference between

db.runCommand( { aggregate: "weather", pipeline: [
{$match : { "days" : { $exists: true} }},
{$limit : 100},
{$project : {
name : 1,
sum : { $add:["$days.4", "$days.4","$days.9"] }
}},
{ $skip : 10 },
{ $limit : 10 },
{ $sort : { sum : -1}},
]);

and

db.runCommand( { aggregate: "weather", pipeline: [
{$match : { "days" : { $exists: true} }},
{$limit : 100},
{$project : {
name : 1,
sum : { $add:["$days.4", "$days.4","$days.9"] }
}},
        { $limit : 10 } ,
{ $skip : 10 },
{ $sort : { sum : -1}},
]);

The result from both commands differs.

Is this caused by the pipelining ?

Eliot Horowitz

unread,
Apr 5, 2012, 10:19:44 AM4/5/12
to mongod...@googlegroups.com
Order is relevant.

If you say,
skip 10, then limit 10
you'll get 11-20

if you say
limit 10
skip 10

you'll get nothing

> --
> You received this message because you are subscribed to the Google Groups
> "mongodb-user" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/mongodb-user/-/8YfbTB9N1xkJ.
> To post to this group, send email to mongod...@googlegroups.com.
> To unsubscribe from this group, send email to
> mongodb-user...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/mongodb-user?hl=en.

Reply all
Reply to author
Forward
0 new messages