[SERVER-1085] slice doesn't work for nested arrays Created: 04/May/10  Updated: 12/Jul/16  Resolved: 05/May/10

Status: Closed
Project: Core Server
Component/s: Querying
Affects Version/s: 1.5.1
Fix Version/s: 1.5.2

Type: Bug Priority: Major - P3
Reporter: Doug Hudson Assignee: Mathias Stearn
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Linux 2.6.31-21-generic #59-Ubuntu SMP x86_64 GNU/Linux


Participants:

 Description   

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



 Comments   
Comment by auto [ 05/May/10 ]

Author:

{'login': 'RedBeard0531', 'name': 'Mathias Stearn', 'email': 'mathias@10gen.com'}

Message: Only $slice outer arrays when nested. SERVER-1085
http://github.com/mongodb/mongo/commit/9e6121b6cb59312f3106b55a2b8c4852cedcbefd

Generated at Thu Feb 08 02:56:01 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.