0

I store a very long string to my document in mongodb server, my document looks like

{
    "_id": ObjectId("5280efdbe4b062c93b582118"),
    "viewID": 1,
    "content": "a very long string"
}

and there are about hundreds of such documents in the same collection. I have indexed the collection.

The problem is that I just execute a very simple query

db.blog.find({viewID:1});

and then get a very long time (over several hours) to wait for the response, and no any error message displayed, server status is OK. But I just add db.blog.find({viewID:1}).limit(1); mongodb returns the result at once.

How can I do to solve the problem or improve the performance??

Here is my explain:

db.blog.find({viewID:1}).explain();
{
    "cursor" : "BtreeCursor viewID_1",
    "isMultiKey" : false,
    "n" : 377,
    "nscannedObjects" : 377,
    "nscanned" : 377,
    "nscannedObjectsAllPlans" : 377,
    "nscannedAllPlans" : 377,
    "scanAndOrder" : false,
    "indexOnly" : false,
    "nYields" : 0,
    "nChunkSkips" : 0,
    "millis" : 45,
    "indexBounds" : {
        "viewID" : [
            [
                1,
                1
            ]
        ]
    },
    "server" : "Server:27017"
}

Here is colStat:

db.blog.stats();
{
    "ns" : "***.blog",
    "count" : 98582,
    "size" : 2330759632,
    "avgObjSize" : 23642.851960804204,
    "storageSize" : 2958364672,
    "numExtents" : 18,
    "nindexes" : 2,
    "lastExtentSize" : 778276864,
    "paddingFactor" : 1,
    "systemFlags" : 1,
    "userFlags" : 0,
    "totalIndexSize" : 6540800,
    "indexSizes" : {
        "_id_" : 4055296,
        "viewID_1" : 2485504
    },
    "ok" : 1
}
Engine Bai
  • 626
  • 1
  • 7
  • 16
  • how many documents do you have and how big is the document? – Salvador Dali Nov 14 '13 at 08:44
  • 3
    Please tell us **how** you indexed the collection. Also, please run your query with `.explain()` added to the end of your command and post the output. It tells us if and how your index is used. – Philipp Nov 14 '13 at 09:00
  • I'm going to guess that viewID is not indexed? – Asya Kamsky Nov 14 '13 at 09:08
  • 1
    Let's get things straight. If you run `db.blog.find({viewID:1});` from shell it takes several hours but if you run `db.blog.find({viewID:1}).explain();` it gives you `"millis" : 45`? – zero323 Nov 14 '13 at 10:43
  • Yes @zero323, but the same situation happens at localhost. – Engine Bai Nov 14 '13 at 10:55
  • Could you define very long string? – Alan Spencer Nov 20 '13 at 14:43
  • @AlanSpencer, it's about thousands of chinese words per documents, and there are hundreds of documents per viewID. – Engine Bai Nov 20 '13 at 15:07
  • What happens when you don't pull back the text - i.e. db.blog.find({viewID:1},{viewID:1}) – Alan Spencer Nov 20 '13 at 15:34
  • @AlanSpencer There is no any response displayed in the terminal after I enter the query command. I wait for a day long, but it still does not have any response after all. – Engine Bai Nov 20 '13 at 15:45
  • This is for the field selection find? find({viewID:1}).limit(1) returns immediately? find({viewID:1}) never returns? have you tried find({viewID:1}).limit(2) etc? – Alan Spencer Nov 20 '13 at 15:54
  • It got no response when executing `find({viewID:1}).limit(x), x>10. I've checked the mongodb log, the server did receive the query request, but no any advanced operation is performed. The mongod service also did not appear at the top3 cpu comsumed processes. I check the network throughput, it's not found high transmission rate, too. I got stuck at last. – Engine Bai Nov 20 '13 at 16:14
  • I execute `find({viewID:1}).limit(1)` and the server returns immediately. – Engine Bai Nov 20 '13 at 16:15

0 Answers0