How to limit mongo query in python

As specified in this question, indexed access will ignore the limit. And count() does not obey limit or skip by default as explained the manual. You can pass with_limit_and_skip=True to make count() work with limit.

print db_data.count(with_limit_and_skip=True)

Or you can iterate the cursor to see limit in effect.

for data in db.myusers.find().limit(2):
    print data

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)