[SERVER-42117] Bad hint (json order) Created: 09/Jul/19 Updated: 06/Dec/22 Resolved: 29/Jul/19 |
|
| Status: | Closed |
| Project: | Core Server |
| Component/s: | Querying |
| Affects Version/s: | None |
| Fix Version/s: | None |
| Type: | Bug | Priority: | Major - P3 |
| Reporter: | Grégory NEUT | Assignee: | Backlog - Triage Team |
| Resolution: | Done | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Attachments: |
|
| Assigned Teams: |
Server Triage
|
| Operating System: | ALL |
| Participants: |
| Description |
|
I have created a collection having a compound index, as :
Then I tried to perform a simple find using this compound index :
And I got the following error :
I have found that changing the order of the names in my find request make it to work :
Which is non sense considering that json do not guarantee keys order. |
| Comments |
| Comment by Danny Hatcher (Inactive) [ 29/Jul/19 ] | |||||||||||||||||||||||
|
To follow up orelsanpls, you could have also resolved this issue by using a Map rather than an Object. As you mentioned, JSON does not preserve order. | |||||||||||||||||||||||
| Comment by Eric Sedor [ 10/Jul/19 ] | |||||||||||||||||||||||
|
Thanks orelsanpls, we are going to attempt a reproduction of this and will update this ticket if we have additional questions. | |||||||||||||||||||||||
| Comment by Grégory NEUT [ 10/Jul/19 ] | |||||||||||||||||||||||
|
I'm using : mongodb v4.0.3 node.js v8.9.4 mongoose@5.6.3 which use the npm packages : - "mongodb": "3.2.7" | |||||||||||||||||||||||
| Comment by Grégory NEUT [ 10/Jul/19 ] | |||||||||||||||||||||||
|
Hello, thank you for replying to this ticket. Yes
resulted in bad hint. Now that I've restarted my program, I do not reproduce, so I strongly guess that the keys that was given for the hint got transmitted to mongodb in the wrong order. Mongoose node.js package is relying on mongodb-native package which just pass the hint option to mongodb (here is what I've found on theirs githubs) : https://github.com/mongodb/node-mongodb-native/blob/master/lib/utils.js Line 165
The behavior of `for ... in` could be specific to the node.js version PS: I didn't knew I could pass the name of the index, thank you for the input, I do use this method now and it works well! | |||||||||||||||||||||||
| Comment by Eric Sedor [ 09/Jul/19 ] | |||||||||||||||||||||||
|
Hi orelsanpls, To hint to the index { "entryDate" : -1, "idParameter" : -1, "idConnectedobject" : -1 } you should be able to pass { "entryDate" : -1, "idParameter" : -1, "idConnectedobject" : -1 } (the key specification) or "entryDate_-1_idParameter_-1_idConnectedobject_-1", the index name. So your original description sounds like what should be expected. For your follow-up comment can you please clarify: Are you saying that { idConnectedobject: -1, idParameter: -1, entryDate: -1 } results in a bad hint even though an index exists on { idConnectedobject: -1, idParameter: -1, entryDate: -1 }? | |||||||||||||||||||||||
| Comment by Grégory NEUT [ 09/Jul/19 ] | |||||||||||||||||||||||
|
Actually I saw that the compound index key order is important as specified in the documentation https://docs.mongodb.com/manual/core/index-compound/ I think it's more of a node.js issue. Because in node.js the order of the keys are not guaranteed which leads to possible issues. My program is in `node.js` using `npm` package `mongoose`, even providing the indexes in the correct order, I get a bad hint :
The indexes list :
|