默认find()是否按_id隐式排序? [英] Does default find() implicitly sort by _id?

查看:65
本文介绍了默认find()是否按_id隐式排序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

默认find()是否按_id隐式排序?

Does default find() implicitly sort by _id?

换句话说,下面列出的2条mongo行是否等效?

In other words, are 2 mongo lines listed below equivalent?

db.collection.find().sort( { "_id" : 1 } )

db.collection.find()

推荐答案

如果未定义sort,则游标将使用自然顺序.

The cursors uses the natural order if there is no sort defined.

https://docs.mongodb. com/manual/reference/method/cursor.sort/#return-natural-order

结果排序

除非您指定sort()方法或使用$ near运算符,否则MongoDB不保证查询结果的顺序.

Unless you specify the sort() method or use the $near operator, MongoDB does not guarantee the order of query results.

以自然顺序退货

$ natural参数根据项目在数据库中的自然顺序返回项目.此排序是内部实现功能,您不应依赖其中的任何特定结构.

The $natural parameter returns items according to their natural order within the database. This ordering is an internal implementation feature, and you should not rely on any particular structure within it.

大多数情况下是插入顺序,但这不能保证.

Most of the time it's the insertion order, but that's not guaranteed.

这篇关于默认find()是否按_id隐式排序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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