Ordering in compound indexes matter. But does the ordering in reads/writes matter? Is mongodb smart enough to reorder the fields based on indexes available?
The code is in python. I read that it is preferable to pass in ordered dictionary using: http://api.mongodb.org/python/current/api/bson/son.html.
But after switching between both ordered and unordered dictionaries, I don't see any difference in performance. Running explain on either options, showed that it evaluated different indexes (allPlans field) and did pick up the index whose order was different from the way it received the query.
Would love if this was confirmed either way.
I am using mongo 2.6. May be mongo added some kind of optimization in their newer versions.
Edit: (added example) For ex:
Index is on {c: 1, a: 1, b: 1}
Intended query: db.tble.find(some_dict)
Which one is better? (in python)
- some_dict = {c: "C", a: "A", b: "B"} # unordered.
- some_dict = bson.son.SON({c: "C", a: "A", b: "B"})
Neither made any difference but it is recommended to use 2nd, I don't know why.