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

Document equality should be independent of field insertion order

    • Type: Icon: Improvement Improvement
    • Resolution: Unresolved
    • Priority: Icon: Minor - P4 Minor - P4
    • None
    • Affects Version/s: None
    • Component/s: Querying
    • Query Execution

      Equality of documents should not depend on the order of the fields. The following documents should be considered equal:

      {a: 1, b: 2} {b: 2, a: 1}

      The above documents would be considered the same document for purposes of unique indexes, and would be considered a match for searching.

      This allows documents to map much more naturally to the native, built-in dictionary types in various languages. Most native dictionary types don't preserve order, and builtin dictionary types that support equality (Python, Ruby) don't compare insertion order. Ruby, which does explicitly preserve insertion order, also still does not consider insertion order for equality; {:a=>1, :b=>2} == {:b=>2, :a=>1} is true.

      This would reduce the need to use inconvenient non-builtin dictionary types, and align documents to typical expectations of dictionary types.

      Note: this is not a recommendation to stop preserving insertion order. Although I don't find that useful, it's not obviously harmful, and it should be possible to do both efficiently.

      Additional discussion at http://groups.google.com/group/mongodb-user/browse_thread/thread/c908e572d6e89c49.

            Assignee:
            backlog-query-execution [DO NOT USE] Backlog - Query Execution
            Reporter:
            glenn Glenn Maynard
            Votes:
            9 Vote for this issue
            Watchers:
            36 Start watching this issue

              Created:
              Updated: