[SERVER-754] way to return region of an embedded array Created: 15/Mar/10  Updated: 12/Jul/16  Resolved: 16/Apr/10

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

Type: Improvement Priority: Major - P3
Reporter: Eliot Horowitz (Inactive) Assignee: Mathias Stearn
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Participants:

 Description   

db.foo.find( {} , { comments :

{ $slice : [ 20,40] }

} )



 Comments   
Comment by auto [ 16/Apr/10 ]

Author:

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

Message: $slice operator for projections (second arg to find) SERVER-754
http://github.com/mongodb/mongo/commit/0cd709783028ee29129d18d82e23abe6221a904a

Comment by Eliot Horowitz (Inactive) [ 13/Apr/10 ]

i'd say apis are split 50/50 on min,max vs start,len for list substring

ruby is start,len and our most common language, so maybe that should be the tie breaker

Comment by Mathias Stearn [ 13/Apr/10 ]

I think simple numbers should work like this this:

$slice: 5 -> first 5
$slice: -5 -> last 5

If there is an array is it better to do range or skip-limit?
$slice: [20, 30] -> objects from 20 to 30
vs
$slice: [20, 10] -> skip 20, limit 10

Comment by Michael Dirolf [ 13/Apr/10 ]

could try to mimic the python slice syntax:
$slice: [3] // 3..end
$slice: [-3] // last 3
$slice: [3, -3] // 3..-3
$slice: [null, 3] // first 3

taking it all the way, could even do:
$slice: [null, null, 2] // all evens
$slice: [null, 10, 3] // every 3rd out of the first 10

Comment by Ash Berlin [ 13/Apr/10 ]

> slice : 3 // first 3?

My PoV as a user is I'd expect this to skip the first 3, i.e return 3..end

-3 returning last 3 makes sense to me

My 2p

Comment by Dwight Merriman [ 13/Apr/10 ]

$slice : 3 // first 3?
$slice : -3 // last 3?

Comment by Dwight Merriman [ 13/Apr/10 ]

{ arr :

{ $slice : [20,40] }

}

?

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