Details

    • Type: Question Question
    • Status: Closed Closed
    • Priority: Major - P3 Major - P3
    • Resolution: Works as Designed
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: None
    • Labels:
      None
    • Backport:
      No
    • # Replies:
      2
    • Last comment by Customer:
      false

      Description

      I have this object that has an array of hashes representing addresses.

      See below:

      > db.customers.find(

      {"_id":"c098443ae4243643b189fc43e071a0a3"}

      )
      { "_id" : "c098443ae4243643b189fc43e071a0a3", "addresses" : [

      { "address1" : "18 W 18th Street", "address2" : "Floor 9", "city" : "New York", "companyName" : "The OpenSky Project", "country" : "US", "firstName" : "Matthew", "lastName" : "Fitzgerald", "phone" : "201-406-1869", "postalCode" : "10016", "slug" : "2fghj2x", "state" : "NY", "subtype" : 2, "type" : "customer" }

      ,

      { "address1" : "101 Main Street", "city" : "Middle America", "country" : "us", "firstName" : "Matthew", "lastName" : "Fitzgerald", "phone" : "201-406-1869", "phoneExtension" : "111", "postalCode" : "55555", "slug" : "fm8x", "state" : "KS", "type" : "customer" }

      ] }

      When I attempt to remove an address using "$pullAll" and unordered hash it does not remove it.

      Ex: This fails
      > db.customers.update(

      { "_id": "c098443ae4243643b189fc43e071a0a3" }

      ,
      { "$pullAll":
      { "addresses":
      [

      { "slug": "fm8x", "type": "customer", "firstName": "Matthew", "lastName": "Fitzgerald", "address1": "101 Main Street", "city": "Middle America", "state": "KS", "postalCode": "55555", "country": "us", "phone": "201-406-1869", "phoneExtension": "111" }

      ]
      }
      }
      )

      Ex: This succeeds

      > db.customers.update(

      { "_id": "c098443ae4243643b189fc43e071a0a3" }

      ,
      { "$pullAll":
      { "addresses":
      [

      { "address1": "101 Main Street", "city": "Middle America", "country": "us", "firstName": "Matthew", "lastName": "Fitzgerald", "phone": "201-406-1869", "phoneExtension": "111", "postalCode": "55555", "slug": "fm8x", "state": "KS", "type": "customer" }

      ]
      }
      }
      )

      Question: Does the order of keys in javascript hash objects matter or is it a MongoDB specific limitation? And what are the rules for ordering of keys in hashes in MongoDB (is it alphabetical by key). Is it ordered at all?

      Regards,
      Matt

        Activity

        Hide
        Scott Hernandez
        added a comment -

        Order matters and it is the order you send them to the server in. The server does not reorder them. Matches are made by basically doing a binary compare of the bson data.

        Each language/driver may order them differently; some languages don't have (insert) ordered map/dict impls.

        BTW, It isn't a hash-map but is more an array (orderd list) of pairs (string, document) as defined by the bson spec.

        For you specific question, you should make sure the order is the same, or use another method to remove the array values (like $elemMatch).

        Show
        Scott Hernandez
        added a comment - Order matters and it is the order you send them to the server in. The server does not reorder them. Matches are made by basically doing a binary compare of the bson data. Each language/driver may order them differently; some languages don't have (insert) ordered map/dict impls. BTW, It isn't a hash-map but is more an array (orderd list) of pairs (string, document) as defined by the bson spec. For you specific question, you should make sure the order is the same, or use another method to remove the array values (like $elemMatch).
        Hide
        Eliot Horowitz
        added a comment -

        BSON is ordered by design, so order does/should matter.

        Show
        Eliot Horowitz
        added a comment - BSON is ordered by design, so order does/should matter.

          People

          • Votes:
            1 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:
              Days since reply:
              3 years, 13 weeks, 3 days ago
              Date of 1st Reply: