I have a peculiar problem with Mongo.
We have a collection of 800k documents with the following structure.
{
"_id" : ObjectId("5bd844199114bab3b2c19fab"),
"u" : 0,
"c" : 0,
"iden" : "343754856",
"name" : "alan",
"email" : "mkasd@abc.com",
"mobile" : "987654321093456",
"expires" : ISODate("2018-11-29T11:44:25.453Z"),
"created" : ISODate("2018-10-30T11:44:25.453Z")
}
We have indexed iden
and name
on which we generally query.
We tried two types of queries.
-
db.Collection.find({"iden": "343754856", "name": "alan", "created":
{"$gt": ....}).count()where "created" is an unindexed field.
-
db.Collection.find({"iden": "343754856", "name": "alan"})
and iterate over all records to filter based on
created
.
However, MongoDB seems to be taking enormous amount of time in executing the second query while it was supposed to be an optimization over 1.
Any leads on what is going wrong here? We are using Go library.