1

I am using mongodb latest version 3.4.10. i have collection name called transaction with 14000 records. the below query i ran it taking to complete 10sec.

command : db.transaction.find({mcCreatedTime : { $gte:ISODate("2017-10-01T00:00:00.000Z"), $lte:ISODate("2017-11-02T23:59:59.000Z")}})

It will return expected record with taking long time around 10 sec. I need to complete the query within msec.

I am using windows 8.1 and 4GB of RAM and 500GB hard disk.

2 Answers2

0

Try creating an index as:

db.transaction.createIndex({mcCreatedTime:1}, {background:true})

You need to take a look at explain to check why your query is slow.

Atish
  • 4,277
  • 2
  • 24
  • 32
0

The best way to get faster query results in a database management system is to build indexes.

Try creating an index on mcCreatedTime field to make it return results faster.

Ascending order: db.transaction.createIndex({'mcCreatedTime':1}) should be able to create the required index.

Mongo DB Index Creation

pRmdk
  • 151
  • 1
  • 10
  • Index created. but the query is result is slow – K.Boopathi 17 Nov 08 '17 at 08:52
  • @K.Boopathi17 can you check if you have implemented both ascending and descending indexes on date column, as both are required for faster results when doing sorting or range search. https://stackoverflow.com/a/10330373/1889046 – pRmdk Nov 08 '17 at 09:59