Skip to content

Commit

Permalink
catch errors
Browse files Browse the repository at this point in the history
  • Loading branch information
rustagir committed Jun 13, 2024
1 parent 2bb9b22 commit 0b8b270
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,12 @@ func main() {
// documents that match the filter
// begin distinct
filter := bson.D{{"enrollment", bson.D{{"$lt", 50}}}}
res := coll.Distinct(context.TODO(), "department", filter)

var arr []string
res.Decode(&arr)
err = coll.Distinct(context.TODO(), "department", filter).Decode(&arr)
if err != nil {
panic(err)
}

fmt.Printf("%s\n", arr)
// end distinct
Expand Down
7 changes: 4 additions & 3 deletions source/includes/usage-examples/code-snippets/distinct.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,11 @@ func main() {

// Retrieves the distinct values of the "title" field in documents
// that match the filter
res := coll.Distinct(context.TODO(), "title", filter)

var arr []string
res.Decode(&arr)
err = coll.Distinct(context.TODO(), "title", filter).Decode(&arr)
if err != nil {
panic(err)
}
// end distinct

// Prints the distinct "title" values
Expand Down
2 changes: 1 addition & 1 deletion source/quick-reference.txt
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ their related reference and API documentation.
:language: go

var results []string
coll.Distinct(context.TODO(), "firstName", bson.D{}).Decode(&results)
err = coll.Distinct(context.TODO(), "firstName", bson.D{}).Decode(&results)

.. output::
:language: go
Expand Down
2 changes: 1 addition & 1 deletion source/usage-examples/distinct.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ collection:
.. literalinclude:: /includes/usage-examples/code-snippets/distinct.go
:start-after: begin distinct
:end-before: end distinct
:emphasize-lines: 6
:emphasize-lines: 7
:language: go
:dedent:

Expand Down

0 comments on commit 0b8b270

Please sign in to comment.