Is it possible to express the following SQL query in mongodb:
SELECT * FROM table AS t WHERE t.field1 > t.filed2;
edit:
To summarize:.
- using a third field storing “field1 – field2” is almost perfect, but requires a little extra maintenance.
- $where will load and eval in JavaScript and won’t use any indexes. No good for large data.
- map/reduce has the same problem and will go trough all records even if we need only one
You can do this using $where:
But:
If performance is an issue better to go with way suggested by @yi_H.