Hello Mongo newbie here. I have a query which works fine but when running against a lot of data and wide date range it can take many seconds or even minutes. I narrowed down the bottle neck which is the following snippet that lies within a couple of for loops. In my current date range the whole query takes less than a second…
db.collection.find({'SecondEvent.Code': "1111"},
{_id: 0, 'TrackTime': 1}).sort({'TrackTime.0': -1}).limit(1)
However what I want to do is get the actual value of the TrackTime which means doing the following…
db.collection.find({'SecondEvent.Code': "1111"},
{_id: 0, 'TrackTime': 1}).sort({'TrackTime.0': -1}).limit(1)[0].TrackTime[0].valueOf()
The whole query now takes about 12 seconds! Is there any other way of getting the time value out for the result without the performance falling over like this?
Any help is much appreciated
Thanks