0

My collection name is trial and data size is 112mb

My query is,

db.trial.find()

and i have added limit up-to 10.

db.trial.find.limit(10).

but the limit is not working.the entire query is running.

2 Answers 2

1

Replace

db.trial.find.limit(10)

with

db.trial.find().limit(10)

Also you mention that the entire database is being queried? Run this

db.trial.find().limit(10).explain()

It will tell you how many documents it looked at before stopping the query (nscanned). You will see that nscanned will be 10.

Sign up to request clarification or add additional context in comments.

Comments

0

The .limit() modifier on it's own will only "limit" the results of the query that is processed, so that works as designed to "limit" the results returned. In a raw form though with no query you should just have the n scanned as the limit you want:

db.trial.find().limit(10)    

If your intent is to only operate on a set number of documents you can alter this with the $maxScan modifier:

db.trial.find({})._addSpecial( "$maxScan" , 11 )

Which causes the query engine to "give up" after the set number of documents have been scanned. But that should only really matter when there is something meaningful in the query.

If you are actually trying to do "paging" then you are better of using "range" queries with $gt and $lt and cousins to effectively change the range of selection that is done in your query.

2 Comments

@user2702383 missing a "dot" . that is corrected. Note that as I say you probably do not need this unless you actually are querying for a specific match that will return more than the results you are "limiting" to, which is essentially what I have said.
Actually the collection trial have imported without the _id into mongodb.my import querie is mongoimport -h localhost --port 27017 -d admin -c trial -u user -p ***** --file /home/Desktop/oad_departments.dump --type csv --headerline do i need to change anythng else in this?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.