You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
docsThis issue is due to a mistake or omission in the mongoosejs.com documentationhelpThis issue can likely be resolved in GitHub issues. No bug fixes, features, or docs necessary
I have searched existing issues to ensure the bug has not already been reported
Mongoose version
6.3.4
Node.js version
16.14.2
MongoDB server version
5.0.9
Description
The docs in $slice: [ <number to skip>, <number to return> ] state that If the number of skiped elements is greater than the number of array elements, the query returns an empty array.
I expected a similar behavior when the skiped number is negative but it wasn't the case (when specifying the number of returned elements).
It seems that that when n (number of skip) is negative and greater than the array size it become 0 like if(n > array.length) return 0 where 0 is the starting referance.
I expected that myCollection.findOne({}, { $slice: [-100, 5] }); to return an empty array same as myCollection.findOne({}, { $slice: [-10, 5] }); to return: [1, 2, 3, 4], meaning it should work same way netagive or possitive. the expected behavior should be in my opinion the same when :
using negative skip with number of return
or when using array.reverse() then a skip with a positive number.
Meaning both return empty array if the skip is too big
The text was updated successfully, but these errors were encountered:
IslandRhythms
added
the
docs
This issue is due to a mistake or omission in the mongoosejs.com documentation
label
Sep 29, 2022
docsThis issue is due to a mistake or omission in the mongoosejs.com documentationhelpThis issue can likely be resolved in GitHub issues. No bug fixes, features, or docs necessary
Prerequisites
Mongoose version
6.3.4
Node.js version
16.14.2
MongoDB server version
5.0.9
Description
The docs in
$slice: [ <number to skip>, <number to return> ]
state that If the number of skiped elements is greater than the number of array elements, the query returns an empty array.I expected a similar behavior when the skiped number is negative but it wasn't the case (when specifying the number of returned elements).
It seems that that when n (number of skip) is negative and greater than the array size it become
0
likeif(n > array.length) return 0
where0
is the starting referance.Steps to Reproduce
Given {array : [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] }
myCollection.findOne({}, { $slice: [-1, 5] });
returns:[ 9, 10]
myCollection.findOne({}, { $slice: [-4, 5] });
returns:[6, 7, 8, 9, 10]
myCollection.findOne({}, { $slice: [-9, 5] });
returns:[1, 2, 3, 4, 5]
myCollection.findOne({}, { $slice: [-10, 5] });
returns:[1, 2, 3, 4, 5]
myCollection.findOne({}, { $slice: [-100, 5] });
returns:[1, 2, 3, 4, 5]
Expected Behavior
I expected that
myCollection.findOne({}, { $slice: [-100, 5] });
to return an empty array same asmyCollection.findOne({}, { $slice: [-10, 5] });
to return:[1, 2, 3, 4]
, meaning it should work same way netagive or possitive. the expected behavior should be in my opinion the same when :Meaning both return empty array if the skip is too big
The text was updated successfully, but these errors were encountered: