The "fully runnable example" from the Find Multiple Documents usage example page declares the results slice that is passed to `cursor.All` as
var results []bson.M
In the case of no results, `results` will remain in an uninitialized state, which will be encoded as `null` in JSON (and BSON).
In contrast, if the results slice is declared as
var results []bson.M = make([]bson.M, 0, 0) // or, equivalently results := make([]bson.M, 0, 0)
In the case of no results, `results` will be fully initialized, and will be encoded as `[]` (the empty array) in JSON.
Need to initialize a nil slice in `cursor.All` when there are no results.
- is related to
-
GODRIVER-2553 docs: cursor.All code in the find API usage example leads users to a Go gotcha in the case of no results (might be bug)
-
- Closed
-