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