Uploaded image for project: 'PHP Legacy Driver'
  1. PHP Legacy Driver
  2. PHP-104

A PHP array with non-consecutive, numeric keys becomes an object in mongodb

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Minor - P4
    • Resolution: Won't Fix
    • Affects Version/s: 1.0.6
    • Fix Version/s: None
    • Component/s: pecl-mongo
    • Labels:
      None
    • Environment:
      php 5.3.1 windows
      mondo 1.0.6 driver
    • # Replies:
      1
    • Last comment by Customer:
      true

      Description

      php example:

      $array = array('a', 'b', 'c');
      unset($array[1]);

      $document = array(
      'embedded' => $array,
      );

      // assuming local
      $mongo = new Mongo();
      $mongo->test->test->insert($document);

      mongodb result:
      { "_id" : ObjectId(...), "embedded" :

      { "0" : "a", "2" : "c" }

      }

      expected:
      ['a', 'c']

      I'm not sure how checking is done at the moment by the driver, but at the point of insert, all keys of the array are still ints, even if they are not consecutive. So, perhaps the difference maker between an object and an array is whether the keys consist of all ints (array), or a mixture of ints and strings etc. (object).

      My workaround for now is to use anything that will 'compact' the keys, like sort(), before inserting arrays.

      I'm aware that people could argue for both behaviours, so I'm logging this bug with the following in mind:

      • if you're not aware, make you aware of the issue
      • if you are aware, to get a relatively final response logged in JIRA as to whether it will be changed, or if it's a wont-fix
      • if it's a wont-fix, to obtain official recommendation of workaround

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                kristina Kristina Chodorow (Inactive)
                Reporter:
                bvnx bvnx
                Participants:
                Last commenter:
                Rathi Gnanasekaran
              • Votes:
                0 Vote for this issue
                Watchers:
                0 Start watching this issue

                Dates

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