[SERVER-22529] search order for embedded documents, and only there Created: 09/Feb/16  Updated: 10/Feb/16  Resolved: 10/Feb/16

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

Type: Bug Priority: Major - P3
Reporter: Nico Schlömer Assignee: Unassigned
Resolution: Duplicate Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Duplicate
duplicates SERVER-5030 Document equality should be independe... Backlog
Operating System: ALL
Participants:

 Description   

When searching for a documents with multiple fields, the order of the fields doesn't matter: Querying for

{color: 'blue', taste: 'salty'}

will return documents that have {color: 'blue', taste: 'salty'} as well as documents that have {taste: 'salty', color: 'blue'}. That's consistent, for example, with lodash/underscore's find [1] and any other find in JS objects I know of.

When it comes to embedded documents, though, mongodb takes a different route:

> Equality matches on an embedded document require an exact match of the specified <value>, including the field order.

(from [2]). This means that the query

{specs: {color: 'blue', taste: 'salty'}}

will NOT return documents with

{specs: {taste: 'salty', color: 'blue'}}

While it is possible to construct element matches that disregard field order [3], the described default behavior for embedded fields is inconsistent with document-level queries. This leads to application errors and in fact regularly bites people [4,5].

Opinions?

[1] https://lodash.com/docs#find
[2] https://docs.mongodb.org/manual/tutorial/query-documents/#exact-match-on-the-embedded-document
[3] https://docs.mongodb.org/manual/tutorial/query-documents/#equality-match-on-fields-within-an-embedded-document
[4] http://stackoverflow.com/q/16002659/353337
[5] https://twitter.com/andrenarchy/status/697041934699917312



 Comments   
Comment by Kelsey Schubert [ 10/Feb/16 ]

Hi nico.schloemer@gmail.com,

Thank you for the report. This ticket is a duplicate of the improvement request in SERVER-5030. Please feel free to review the discussion on the ticket, vote for it, and watch it for updates.

Kind regards,
Thomas

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