Does Key order matter in a MongoDB BSON doc?

元气小坏坏 提交于 2019-12-07 06:22:54

问题


I know certain commends need the hashmap / dictionary to be ordered, but does the actual BSON document in MongoDB matter and would the index still work?

E.g.

db.people.ensureIndex({LName:1, FName:1});

Would it work on both:

{LName:"abc", FName:"def"}, 
{FName:"ghi", LName:"jkl"} 

?

Thanks


回答1:


The order of a document's properties does not affect indexing.

You can see this for yourself by running this query:

db.people.find({LName: "abc"}).explain()

and then this query:

db.people.find({LName: "jkl"}).explain()

you should see that MongoDB will use the index in both cases (the cursor property should be something like "BtreeCursor LName_1_FName_1").



来源:https://stackoverflow.com/questions/4453424/does-key-order-matter-in-a-mongodb-bson-doc

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!