Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MongoDB query comparing 2 fields in same collection without $where

Tags:

mongodb

Does MongoDB supports comparing two fields in same collection by using native operators (not $where and JavaScript)? I already looked at similar questions and all answers used $where / JavaScript.

MongoDB documentation clearly states that:

JavaScript executes more slowly than the native operators listed on this page, but is very flexible.

My primary concern is speed and I would like to use indexes if possible. So is comparing two fields in MongoDB possible without using JavaScript?

like image 642
Christian P Avatar asked Jan 12 '12 14:01

Christian P


1 Answers

This is not currently possible, but it will be possible through the new aggregation framework currently under development (2.1+). This aggregation framework is native and does not rely on relatively slow JavaScript execution paths.

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

like image 144
Remon van Vliet Avatar answered Oct 22 '22 11:10

Remon van Vliet