[DOCS-16617] [Server] Add example of using $slice (projection) with an array as 1st parameter Created: 30/Jan/24  Updated: 01/Feb/24

Status: Backlog
Project: Documentation
Component/s: manual, Server
Affects Version/s: None
Fix Version/s: None

Type: Task Priority: Minor - P4
Reporter: Jérôme Tamarelle Assignee: Unassigned
Resolution: Unresolved Votes: 0
Labels: request
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

URL(s): https://www.mongodb.com/docs/manual/reference/operator/projection/slice/
Participants:
Days since reply: 1 week, 1 day ago

 Description   

The $slice(projection) operator can be used with an array as 1st parameter, like the $slice(aggregation) operator.

 

db.posts.find( {}, { com: { $slice: ["$comments", 1, 3] } } ) 

 

This is told by the server error when we use only 1 parameter in an array

 

db.posts.find( {}, { comments: { $slice: [3] } } ) 

Invalid $slice syntax. The given syntax { $slice: [ 3 ] } did not match the find() syntax because :: Location31272: $slice array argument should be of form [skip, limit] :: The given syntax did not match the expression $slice syntax. :: caused by :: Expression $slice takes at least 2 arguments, and at most 3, but 1 were passed in.

 

The review must be done by the server team, I've only found this undocumented supported feature.

 


Generated at Thu Feb 08 08:15:45 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.