Mongo DB 在与 find 选项一起使用时显示记录的依据是什么? [英] On What basis does the Mongo DB displays the records when used with find option?

查看:29
本文介绍了Mongo DB 在与 find 选项一起使用时显示记录的依据是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 MongoDB 作为我的应用程序的数据库

I am using MongoDB as DataBase for my application

我有一个关于 Mongo DB 查找操作的问题.

I have a question with respect to Mongo DB find operation .

假设我在一个字段上有两个/三个相同的记录,请说数据库中存在的集合中的符号.

Assume if i have two / three same records on a field say symbol in the collection present in the Database .

db.collection.find( { "symbol": "GOOG" })

db.collection.find( { "symbol": "GOOG" })

Mongo DB 显示第一条记录的依据是什么??

On What basis does the Mongo DB shows the First record ??

编辑部分

我的测试环境和生产环境中都存在具有相同数据的 Mongo DB.

I am having Mongo DB present in my Test Environment and as well as in Production Environment with the same data .

我的问题是,

什么时候做

db.bios.find( { "name": "FOOGY" } )

db.bios.find( { "name": "FOOGY" } )

两种环境下显示的数据(第一条记录)有区别??

There is a difference in the Data that is displayed (the first record ) in two environments ??

请告诉我为什么在发出相同的命令时在两种环境中显示的数据会发生变化

Please let me know why there is a variation in the Data that is dislayed in two environments when issued the same commnad

db.bios.find( { "name": "FOOGY" } )

db.bios.find( { "name": "FOOGY" } )

请让我知道是否有任何拇指规则应该先播种什么记录??

Please let me know is there any thumb rule that what record should be sown first ??

推荐答案

除非您明确排序,否则它们以任何顺序存储在磁盘上(称为 自然顺序).如果您关心返回记录的顺序,请为您的 find 提供 sort 选项.

Unless you explicitly sort, it's whatever order they happen to be stored in on disk (called natural order). If you care what the order of the returned records is, provide the sort option to your find.

为了解决您更新的问题:是的,如果您将相同的文档存储在单独的 MongoDB 实例中,那么它们肯定可以彼此不同.由于更新导致文档在磁盘上重新定位,因此即使是单个 MongoDb 实例也可以随着时间的推移以不同的顺序返回文档.

To address your updated question: yes, if you have the same docs stored in to separate MongoDB instances, they definitely can come back in a different from one another. Even a single MongoDb instance can return the docs in a different order over time as documents are relocated on disk due to updates.

这篇关于Mongo DB 在与 find 选项一起使用时显示记录的依据是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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