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

Handle negative array offsets consistently

    XMLWordPrintableJSON

Details

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: Minor - P4 Minor - P4
    • None
    • None
    • Write Ops
    • None
    • ALL

    Description

      update, find, and $slice don't agree about what negative integers mean: $slice treats negatives as offsets from the right end of the array, find doesn't (seem to) support them at all, and update does something weird:

      db.a.insert({ x : [] });
      db.a.update({}, { $set : { "x.-1" : 1 } } );
      db.a.update({}, { $set : { "x.-1" : 2 } } );
      db.a.update({}, { $set : { "x.-1" : 3 } } );
      db.a.find()
      { "_id" : ObjectId("4f849706fdbf7f54d34ba15b"), "x" : [ 3, 2, 1 ] }
      db.a.find({}, { x: { $slice : -1 } })
      { "_id" : ObjectId("4f849706fdbf7f54d34ba15b"), "x" : [ 1 ] }
      db.a.find({ "x.-1" : 1 });

      I didn't check what aggregation framework operators do...

      Attachments

        Activity

          People

            Unassigned Unassigned
            richard.kreuter Richard Kreuter (Inactive)
            Votes:
            1 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: