Uploaded image for project: 'Documentation'
  1. Documentation
  2. DOCS-16617

[Server] Add example of using $slice (projection) with an array as 1st parameter

      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.

       

            Assignee:
            ian.fogelman@mongodb.com Ian Fogelman
            Reporter:
            jerome.tamarelle@mongodb.com Jérôme Tamarelle
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved:
              14 weeks ago