Mongodb总行数限制

I have some problem with a Restfull interface of mongoDB.

I have submitted this query --> http://127.0.0.1:28017/db/collection/?limit=0(I used limit = 0 because I want to find all my result with an ajax request), and the result in terms of number of rows is "total_rows" : 38185.

But if in my shell if I execute db.collection.count() the result was 496519.

Why I have these difference? Is it possible to get the same result with an ajax request?

Thanks in advance for your help.

I'm sure that results were not impacted by numbers of rows nor directly MongoDB, but indicates be Webserver (at time created to tasks admin). It’s possibly to be the payload size of response break by Webserver something like HTTP error 413 (entity to larger).

In my tests i see entries in log as "[websvr] killcursors: found 1 of 1". This will kill opened cursor between the client (in the case web server) and MongoDB. Most drivers not need call OP_KILL_CURSORS because the MongoDB define a timeout of 10 minutes by default.

Go back for tests i conclude that size payload of response of web server (built-in MongoDB) is limited 38~40MB. Let me show my analyze.

I created a collections with 1,260,000 documents. In REST web interface make query that results total_rows: 379,677 (or avgObjSize * total_rows = 38MB).

db.manyrows.stats()
{
     "ns" : "forum.manyrows",
     "count" : 1260000,
     "size" : 125101640,
     "avgObjSize" : 99.28701587301587,
     "storageSize" : 174735360,
     "numExtents" : 12,
     "nindexes" : 1,
     "lastExtentSize" : 50798592,
     "paddingFactor" : 1,
     "systemFlags" : 1,
     "userFlags" : 0,
     "totalIndexSize" : 48753488,
     "indexSizes" : {
          "_id_" : 48753488
     },
     "ok" : 1
}

====== web output

{"total_rows" : 379677 ,  "query" : {} ,  "millis" : 6793}

Continuing... dropped/removed some documents of collection to fit 38MB. Do new query results in all documents thats results 379642 of 379642 or 38MB.

> db.manyrows.stats()
{
     "ns" : "forum.manyrows",
     "count" : 379678,
     "size" : 38172128,
     "avgObjSize" : 100.53816128403543,
     "storageSize" : 174735360,
     "numExtents" : 12,
     "nindexes" : 1,
     "lastExtentSize" : 50798592,
     "paddingFactor" : 1,
     "systemFlags" : 1,
     "userFlags" : 0,
     "totalIndexSize" : 12329408,
     "indexSizes" : {
          "_id_" : 12329408
     },
     "ok" : 1
}

=== web output

{"total_rows" : 379678 ,  "query" : {} ,  "millis" : 27325}

New samples with other collections: Results 39MB with (“avgObjSize": 3440.35 * "total_rows": 11395 = 39MB)

> db.messages.stats()
{
     "ns" : "enron.messages",
     "count" : 120477,
     "size" : 414484160,
     "avgObjSize" : 3440.3592386928626,
     "storageSize" : 518516736,
     "numExtents" : 14,
     "nindexes" : 2,
     "lastExtentSize" : 140619776,
     "paddingFactor" : 1,
     "systemFlags" : 1,
     "userFlags" : 1,
     "totalIndexSize" : 436434880,
     "indexSizes" : {
          "_id_" : 3924480,
          "body_text" : 432510400
     },
     "ok" : 1
}

=== web output:

{ "total_rows" : 11395 , "query" : {} , "millis" : 2956 }

You can try make query with a microframework like Bottle.