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

Does order of keys matter in hashes?

    XMLWordPrintableJSON

Details

    • Icon: Question Question
    • Resolution: Done
    • Icon: Major - P3 Major - P3
    • None
    • None
    • None
    • None

    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

      Attachments

        Activity

          People

            Unassigned Unassigned
            tirnanog06 Matthew Fitzgerald
            Votes:
            1 Vote for this issue
            Watchers:
            5 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: