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

Handle negative array offsets consistently

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Minor - P4 Minor - P4
    • None
    • Affects Version/s: None
    • Component/s: Write Ops
    • Labels:
      None
    • ALL

      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...

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

              Created:
              Updated:
              Resolved: