简体   繁体   中英

On What basis does the Mongo DB displays the records when used with find option?

I am using MongoDB as DataBase for my application

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" })

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

Edited part

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

my question is ,

when i do

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" } )

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

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 .

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.

It returns the records in whatever order it finds them. It's not random, but it's not predictable either, and even when you find a pattern, it could suddenly be totally different for some reason. When you want a specific order, sort the results, or include an unique index in your query and use findOne().

The documents actually come back in find order not $natural order and, as told, about $natural order, when I asked the question long ago in the Google Group, they are not the same.

The find order has an element of randomness to it but it is not completely random.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM