Slow query over MongoDB with index

3

I have a MongoDB collection with about 1.7 million documents, averaging 6kb per document. The bank is in a reasonable machine, with 6GB of RAM and 4 CPUs.

This collection has an index on all fields in my query.

The index has the attributes below (String, String and Date) and has the size of a measly 15 mb. (Checked for MongoDB Compass)

{
    "Unit" : 1.0,
    "VendorCode" : 1.0,
    "EmissionDate" : 1.0
}

However, when I squeeze any query on top of the collection, even though it is restricted to index attributes, it takes a long time to complete.

Query Example

db.Collection.find({
        'Unit': '016406',
        'EmissionDate': {$gte: new ISODate('2018-08-01')}
    }, {
        'Unit': 1,
        'VendorCode': 1,
        'EmissionDate': 1
    })

In my SQL experience, a query that is restricted to an index of this size would return the result in fractions of a second. However when I run the query, either directly in the shell or with Robo3T, it takes more than 10 minutes!

The impression you give me is that even the data being all contained in the index, when there is document match, it looks just like the storage.

I'm not taking into account some basic precept of MongoDB? What options would guide me to investigate this problem?

    
asked by anonymous 04.09.2018 / 22:53

0 answers