Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-30197

$eq-ordered and $eq-unordered

    • Type: Icon: Improvement Improvement
    • Resolution: Unresolved
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: None
    • None
    • Query Optimization

      It would be nice if there where specialized variants of the $eq operator for matching in an order-Independent fashion.

      $eq-unordered could be used on arrays to implement sets:

      > db.test.insert({_id: 1, colors: ["red", "blue"]})
      > db.test.find({colors: {$eq-unordered: ["blue", "red"]}})
      {_id: 1, colors: ["red", "blue"]})
      

      For objects it would be useful, since json objects are usually treated as order-independent by most programming environment, so this would make subdocument matching easier.

      Without this we have to do:

      > db.test.insert({_id: 1, doc: {name: "Arthur", occupation: "Bulldozer-preventer"}})
      > db.test.insert({_id: 2, doc: {name: "Arthur", occupation: "Bulldozer-preventer", do_not_ignore: "do not ignore this field"}})
      > db.test.find({"doc.name": "Arthur", "doc.occupation": "Bulldozer-preventer"})
      {_id: 1, doc: {name: "Arthur", occupation: "Bulldozer-preventer"}}
      {_id: 2, doc: {name: "Arthur", occupation: "Bulldozer-preventer", do_not_ignore: "do not ignore this field"}}
      

      Note how the second document also is matched – I believe there is no syntax to prevent the match if there are extra fields so an exact order independant match is not possible.

      With this we could do:

      > db.test.find({doc: {$eq-unordered: {occupation: "Bulldozer-preventer", name: "Arthur"}}})
      {_id: 1, doc: {name: "Arthur", occupation: "Bulldozer-preventer"}}
      

            Assignee:
            backlog-query-optimization [DO NOT USE] Backlog - Query Optimization
            Reporter:
            karo Karolin Varner
            Votes:
            0 Vote for this issue
            Watchers:
            14 Start watching this issue

              Created:
              Updated: