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

Inclusion of array slice may be specified with exclusion of other fields

    XMLWordPrintableJSON

Details

    • 0.25

    Description

      In the following URL, we explain how we may use projection on fields to limit the output structure of a document.

      http://docs.mongodb.org/manual/tutorial/project-fields-from-query-results/

      While one may use $slice to limit an array to a few of its elements, it is possible to select parts of that array, but also remove other fields as such

      db.t.insert({_id:1, name:'mongouser', age:100, message:'try the new mongodb version 2.6', v:[1,2,3,4,5,6]})

      Then try

      db.t.find({},{name:1, age:1, message:0})
      vs
      db.t.find({},{name:0, age:0, v:{$slice:[-3,3]} })

      Please modify You cannot combine inclusion and exclusion semantics in a single projection with the exception of the _id field.

      Attachments

        Activity

          People

            Unassigned Unassigned
            rohit.nijhawan@10gen.com rohit.nijhawan@10gen.com
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:
              6 years, 3 weeks, 1 day ago