mongodb - Is it possible to find by expression using the mongo find function? -


say have data this:

{   a: 2,   b: 1 } 

i want find values greater b.

i can using aggregate pipeline, or using $where, can using plain old find function? feels ought possible this, in aggregate pipeline:

db.collection.find({   a: {     '$gt': '$b'   } }) 

(this doesn't work)

is not supported, , if not, design, philosophy or omission? alternately, being idiot?

i don't think mongodb yet supports expressions accommodate comparison between 2 or more fields other $where expression or aggregation framework uses same query language regular find.

the best store in document denormalized flag, isgreater stores boolean (a - b > 0) can query find()

db.collection.find({"isgreater": true}) 

there similar jira ticket here server-7623 planned not scheduled.


Comments