MongoDB查询比较没有$ where的同一集合中的2个字段 [英] MongoDB query comparing 2 fields in same collection without $where
问题描述
MongoDB是否支持使用本地运算符(而不是$ where和JavaScript)比较同一集合中的两个字段? 我已经看过相似
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 文档明确指出:
MongoDB documentation clearly states that:
JavaScript的执行速度比本页上列出的本机运算符慢,但是非常灵活.
JavaScript executes more slowly than the native operators listed on this page, but is very flexible.
我主要关心的是速度,如果可能的话,我想使用索引.那么在不使用JavaScript的情况下可以比较MongoDB中的两个字段吗?
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?
推荐答案
当前无法实现,但是通过当前正在开发的新聚合框架(2.1+)可以实现.该聚合框架是本机框架,不依赖于相对较慢的JavaScript执行路径.
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.
有关更多详细信息,请检查 http://www.mongodb.org/display/DOCS/Aggregation+Framework一个> 以及 https://jira.mongodb.org/browse/SERVER-447
For more details check http://www.mongodb.org/display/DOCS/Aggregation+Framework and the progress at https://jira.mongodb.org/browse/SERVER-447
这篇关于MongoDB查询比较没有$ where的同一集合中的2个字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!