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

Slice projection not working as expected

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 1.0.3
    • Component/s: Core API, CRUD
    • Labels:
      None
    • Environment:
      Ubuntu: 19.04
      Go : 1.12.1 linux/amd64

      $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.

       

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

              Created:
              Updated:
              Resolved: