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

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

    XMLWordPrintableJSON

Details

    • Icon: Task Task
    • Resolution: Unresolved
    • Icon: Minor - P4 Minor - P4
    • None
    • None
    • manual, Server

    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.

       

      Attachments

        Activity

          People

            Unassigned Unassigned
            jerome.tamarelle@mongodb.com Jérôme Tamarelle
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              1 week, 1 day ago