Mongo 2.6 索引 - 查询结果顺序 [英] Mongo 2.6 indexing - query result order

查看:56
本文介绍了Mongo 2.6 索引 - 查询结果顺序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们在我们的应用程序中使用 Mongo 2.6.我们从 2.4 版本升级到 2.6 版本.

We are using Mongo 2.6 in our application. We upgraded from 2.4 to 2.6 version.

mongo 2.6 查询时是否会根据不同的单个索引保持顺序.

Will the order be maintained in case of mongo 2.6 query based on different individual indexes.

谢谢.

推荐答案

只要您在查询中明确使用 sort(),顺序将在 2.4 版中保持不变.如果您的查询未使用 sort() 指定排序顺序,则 Mongo DB 2.6 中的更改可能会影响查询的结果顺序.MongoDB 现在可以使用多个索引的交集来完成查询.如果您有两个单独的索引:

As long as you explicitly use sort() in your queries, the order will remain the same in version 2.4. If your queries don't specify sorting order using sort(), there is a change in Mongo DB 2.6 that may affect the result order of your queries. MongoDB can now use the intersection of multiple indexes to fulfill queries. If you have two individual indexes:

db.collection.ensureIndex({A: 1})
db.collection.ensureIndex({B: 1})

而您没有复合索引:

db.collection.ensureIndex({A: 1, B: 1})

查询 db.collection.find({A : a, B: b}) 在 2.6 版本中将返回按 A 和 B 排序的结果.在 2.4 版本中,它仅按 A 排序.有关更多详细信息,请查看此 http://docs.mongodb.org/manual/core/index-intersection/

The query db.collection.find({A : a, B: b}) will return the results sorted by both A and B in version 2.6. In version 2.4, it is sorted by A only. For more details, check out this http://docs.mongodb.org/manual/core/index-intersection/

这篇关于Mongo 2.6 索引 - 查询结果顺序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆