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

slice doesn't work for nested arrays

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 1.5.2
    • Affects Version/s: 1.5.1
    • Component/s: Querying
    • None
    • Environment:
      Linux 2.6.31-21-generic #59-Ubuntu SMP x86_64 GNU/Linux

      Performing slice on an array of arrays results in unexpected behavior. The returned slice is altering the elements.

      Examples:
      > db.slicetest.insert(

      {items: [["a", 1], ["b", 2], ["c", 3]]}

      )
      > db.slicetest.find()

      { "_id" : ObjectId("4be05dbad9e167ecfebc17ce"), "items" : [ [ "a", 1 ], [ "b", 2 ], [ "c", 3 ] ] }

      > db.slicetest.find({}, {items: {$slice: 1}})

      { "_id" : ObjectId("4be05dbad9e167ecfebc17ce"), "items" : [ [ "a" ] ] }

      This one is correct:
      > db.slicetest.find({}, {items: {$slice: 2}})

      { "_id" : ObjectId("4be05dbad9e167ecfebc17ce"), "items" : [ [ "a", 1 ], [ "b", 2 ] ] }

      > db.slicetest.find({}, {items: {$slice: [1,1]}})

      { "_id" : ObjectId("4be05dbad9e167ecfebc17ce"), "items" : [ [ 2 ] ] }

      > db.slicetest.find({}, {items: {$slice: [2,1]}})

      { "_id" : ObjectId("4be05dbad9e167ecfebc17ce"), "items" : [ [ ] ] }

      > db.slicetest.find({}, {items: {$slice: [1,2]}})

      { "_id" : ObjectId("4be05dbad9e167ecfebc17ce"), "items" : [ [ 2 ], [ 3 ] ] }

      Issue reported on mongo-user:
      http://groups.google.com/group/mongodb-user/browse_thread/thread/e84758d6a77ead8b

            Assignee:
            mathias@mongodb.com Mathias Stearn
            Reporter:
            crudson Doug Hudson
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: