I have applied index on embedded document field which is of type date. Due to unpredictable behavior of MongoDB query with $lt & $gt operators I am trying to use min() max() functions of Cursor which force both lower & upper bounds on the index. But when I used it, it gave me error:
planner returned error: unable to find relevant index for max/min query"
Query looks like:
db.user.find().min({'record.date':ISODate("2014-12-01")}).max({'record.date':ISODate("2014-12-01")}).explain()
I have indexed the field 'record.date'. I even tried to force it with hint() but of no use. It showed me this error:
planner returned error: hint provided does not work with min query"
Somewhere on the Internet I saw on one of the forums that we can query with embedded fields in min(), max() functions. Field 'record' is an array of sub-documents. I have another field of type date in main document for which min(), max() worked fine (this field is indexed too). Can anyone guess why is this happening?
sample document: user:
{name:'ad',dob: ISODate('yyyy-mm-dd'),createdAt: ISODate(),...,record:[
{date:ISODate:(),... },...]}
Index was created as:
db.user.ensureIndex({'record.date':1})
Thanks.