I would like to speed up the query in my mongoDB, which uses $ where to compare two fields in a document, which seems very slow.
My query looks like this:
db.mycollection.find({ $where : "this.lastCheckDate < this.modificationDate})
What I would like to do is add a field to my document, i.e. isCheckDateLowerThenModDate , on which I could probably execute a much faster request:
db.mycollection.find({"isCheckDateLowerThenModDate":true})
I am completely new to mongoDB, I do not know how to do this. I would appreciate if anyone could give me some tips or examples on
- How to initialize such a field in an existing collection
- How to save this field. This means how to update this field when changing
lastCheckDate or modificationDate .
Thanks in advance for your help!
source share