MongoDB query comparing 2 fields in one collection without $ where

Does MongoDB support comparing two fields in one collection using its own operators (and not $ where and JavaScript)? I already looked at similar questions and all the answers were used in $ where / JavaScript.

The MongoDB documentation clearly states that:

JavaScript is slower than the native operators listed on this page, but very flexible.

My main concern is speed, and I would like to use indexes if possible. So, is it possible to compare two fields in MongoDB without using JavaScript?

+7
source share
2 answers

This is currently not possible, but it is possible due to the new aggregation structure, which is under development (2.1+). This aggregation structure is native and independent of the relatively slow JavaScript execution paths.

Read more ... http://www.mongodb.org/display/DOCS/Aggregation+Framework and progress at https://jira.mongodb.org/browse/SERVER-447

+5
source

From reading the documentation you are linking, it does not look like MongoDB is able to compare two properties of a document using only its own operators.

Perhaps you yourself can change the documents themselves (and / or the code that stores the documents) to include a boolean property with the value obtained as a result of the comparison (in time mode), and then simply request a new property as necessary. You can even index it for better performance.

+2
source

All Articles