In MySQL it is possible to apply native function on a filed in where clause. For example.
SELECT * FROM t WHERE DATE(the_date) < '2012-11-19';
or
SELECT * FROM t WHERE a+b < 20;
Now, is it possible to use a function on condition field of mongoose query? Let’s say I’m querying something like this:
tSchema.find({a+b: {$lt: 20}}, callback);
No, you can’t create computed columns with
find, so you’d have to useaggregatefor this which is more flexible, but also slower.Like this:
For completeness, I should note that you can do this with
findand a$wherefilter, but the performance of that is terrible, so it isn’t recommended. Like so: