user2439903
user2439903

Reputation: 1305

Query time in MongoDB taking long time?

I am new to MongoDB, I have started using it since I have a requirement where there are around 300 Million documents and have to perform some queries on them. So I have created a collection where the structure resembles:

LogsCollection:

{  LogID, LogName, Version, Serial, Year, Month, Day, Feature { FeatureID, Name, Hour, Minute, second, millisecond  }}

I have inserted 300 Million documents into the collection using C# drvier. So each document is a BSONDocument type.

Now I am trying to query the number of documents with the Year - 2012. The query time is more than 15 mins. Is this the expected behavior for the 300 Million documents I have inserted or Is mongoDB expected to give better performance?

I am also doubting whether the structure I have created in the collection is correct. Can anyone guide me with this?

The queries are basically based on the Date or time and FeatureID.

Upvotes: 3

Views: 3821

Answers (1)

Salvador Dali
Salvador Dali

Reputation: 222899

For sure this is not an expected behavior.

I would recommend to do some changes: because you are new to mongodb I assume that you do not have indexes on your documents, and therefore it makes a full scan (check every document). It is a good practice to have indexes on the keys you are going to do frequent search. So do the following:

db.logs.ensureIndex({'Year': 1})
db.logs.ensureIndex({'FeatureID': 1})

Another thing, I would recommend to convert this date/time keys into Date() fields and then perform time range queries.

But at the beginning just try to make an index and see the performance. Do not forget about explain operator to understand what mongodb is doing behind the hood.

P.S. after your commend about querying on different time options, I would actually suggest to convert to mongo date. You can look at my previous answer how to do something like this (surely you need to modify it to make what you want, but the idea is the same).

Upvotes: 4

Related Questions