Uploaded image for project: 'Go Driver'
  1. Go Driver
  2. GODRIVER-1116

Slice projection not working as expected

    XMLWordPrintable

Details

    • Bug
    • Status: Closed
    • Major - P3
    • Resolution: Community Answered
    • 1.0.3
    • None
    • Core API, CRUD
    • None
    • Ubuntu: 19.04
      Go : 1.12.1 linux/amd64

    Description

      $slice projection is not working as expected in the go driver. I am using below code to fetch 5 elements from the nested array.

       

       

      collection := db.Collection("products")
      skip := (page - 1) * size
      opt := options.FindOptions {
       Limit: &size,
       Skip: &skip,
       Projection: bson.D {{"products", "{ $slice: 5 }"}, {"name", ""}},
      }
       
      cur, err := collection.Find(c, bson.D{}, &opt)

       

      The above code is returning all elements of product array instead of only 5.

       

      Attachments

        Activity

          People

            connie.yu@mongodb.com Run Tian Yu (Inactive)
            anidotnet Anindya Chatterjee
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: