Performing slice on an array of arrays results in unexpected behavior. The returned slice is altering the elements.
Examples:
> db.slicetest.insert(
)
> db.slicetest.find()
> db.slicetest.find({}, {items: {$slice: 1}})
{ "_id" : ObjectId("4be05dbad9e167ecfebc17ce"), "items" : [ [ "a" ] ] }This one is correct:
> db.slicetest.find({}, {items: {$slice: 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