[SERVER-28055] How does mongodb guarantee the compound index order with javascript un-ordered object literal creation? Created: 19/Feb/17  Updated: 24/Feb/17  Resolved: 24/Feb/17

Status: Closed
Project: Core Server
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Question Priority: Major - P3
Reporter: Roben Assignee: Unassigned
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Participants:

 Description   

Such as db.products.createIndex(

{ "item": 1, "stock": 1 }

)
Quoted from https://docs.mongodb.com/manual/tutorial/sort-results-with-indexes/
You can specify a sort on all the keys of the index or on a subset; however, the sort keys must be listed in the same order as they appear in the index.
As there is no order in javascript object, how could mongodb get an order from that?



 Comments   
Comment by Mark Agarunov [ 24/Feb/17 ]

Hello narychen,

Thanks for your report. While you are correct that the ECMAScript specification does not specfify the ordering or enumeration of an object's properties, the specific implementation used in the context of the index is ordered in MongoDB's query interface.

If you would like to get more information about the specific implementation details of MongoDB's interface, consider making a post on the MongoDB Developer User Group.

Please note that SERVER project is for reporting bugs or feature suggestions for the MongoDB server. For MongoDB-related support discussion please post on the mongodb-user group or Stack Overflow with the mongodb tag. A question like this involving more discussion would be best posted on the mongodb-user group.

Thanks,
Mark

Generated at Thu Feb 08 04:17:00 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.