[SERVER-6149] $slice operator- skipping n elements from the end of an array where n > than array length doesn't return null values Created: 20/Jun/12  Updated: 06/Dec/22  Resolved: 05/Jul/19

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

Type: Bug Priority: Minor - P4
Reporter: Jenna deBoisblanc Assignee: Backlog - Query Team (Inactive)
Resolution: Done Votes: 2
Labels: query-44-grooming
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
Assigned Teams:
Query
Operating System: ALL
Participants:

 Description   

Consider the document:
{_id: 1, a : [1,2,3,4,5]}

db.collection.find({}, {a : {$slice : [-10, 1]}}) returns
{_id : 1, a : [1]}

whereas
db.collection.find({}, {a : {$slice : [10, 1]}}) returns
{_id : 1, a : []}



 Comments   
Comment by David Storch [ 05/Jul/19 ]

As far as I can tell, this is the correct behavior, so I'm going to close this ticket as Works as Designed. We interpret -10 to mean "start from the beginning of the array" when there are fewer than 10 array elements.

Comment by Rick Cotter [ 09/Aug/12 ]

Especially important to enable viewing in reverse order:

  • since embedded arrays cannot be sorted
  • cannot not be inserted (thus storing in reverse sort)
Generated at Thu Feb 08 03:10:53 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.