pymongo doesn't obey limit, skip

1,044 views
Skip to first unread message

Venkat

unread,
Feb 21, 2012, 4:32:46 AM2/21/12
to mongodb-user
Hi,

I am new to mongodb trying to use it for my work. I use pymongo from
python. I have pymongo driver. The limit and skip arguments are not
honored by pymongo.

>>> col.find(limit=10, skip=10).count()
17
>>> col.find().count()
17
>>>

Can you suggest me any way out?

Raxit Sheth

unread,
Feb 21, 2012, 4:35:51 AM2/21/12
to mongod...@googlegroups.com
>>col.find(param).limit(10)

append limit after find().


--
You received this message because you are subscribed to the Google Groups "mongodb-user" group.
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.


Venkat

unread,
Feb 21, 2012, 4:39:07 AM2/21/12
to mongodb-user
My complete code looks like,

from pymongo import Connection
con = Connection()
db = con['db_name']
col = db['coll_name']

result = col.find(limit = 10, skip = 10)

Is this usage fine?

jm

unread,
Feb 21, 2012, 4:39:12 AM2/21/12
to mongodb-user
I think count() is supposed to return the number of results as if no
limit/skip were given. Try to iterate the results, it should be fine.

Venkat

unread,
Feb 21, 2012, 4:42:32 AM2/21/12
to mongodb-user
@Jim

Nope. I am able to iterate over all the element that count shows

@Raxit

What ever you suggested doesn't help.

>>> res = col.find().limit(10)
>>> res.count()
17
>>> res[16]
{u'status_code': 200, u'_id': ObjectId('4f429233f36a331187000000'),
u'ip_url': u'http://ymail.com', u'op_url': u'http://mail.yahoo.com',
u'error_str': u'N/A'}

Raxit Sheth

unread,
Feb 21, 2012, 5:00:51 AM2/21/12
to mongod...@googlegroups.com
my bad. mixedup with other lang and other stuff.

Nat

unread,
Feb 21, 2012, 5:40:28 AM2/21/12
to mongod...@googlegroups.com
If you read the manual, you will know why. RTFM.
http://api.mongodb.org/python/current/api/pymongo/cursor.html

kesor

unread,
Feb 21, 2012, 6:51:52 AM2/21/12
to mongodb-user
The method signature (in pymongo) holds a clue to your mystery.

def count(self, with_limit_and_skip=False)

When using .count() on a cursor, default is to ignore limit and skip
unless you specify otherwise.

Venkat

unread,
Feb 21, 2012, 7:20:31 AM2/21/12
to mongodb-user
Thanks kesor. I found it out by going through pymongo code. Thanks.
Reply all
Reply to author
Forward
0 new messages