Skip to content

Commit d6e987e

Browse files
author
iwysiu
committed
GODRIVER-888 update GoDoc example for cursor
Change-Id: Ie95f667da2814e292f68c874eef89387327174f7
1 parent ec0d36b commit d6e987e

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

mongo/doc.go

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,21 @@
3535
// if err != nil { log.Fatal(err) }
3636
// defer cur.Close(context.Background())
3737
// for cur.Next(context.Background()) {
38-
// raw, err := cur.DecodeBytes()
39-
// if err != nil { log.Fatal(err) }
40-
// // do something with elem....
38+
// // To decode into a struct, use cursor.Decode()
39+
// result := struct{
40+
// Foo string
41+
// Bar int32
42+
// }{}
43+
// err := cur.Decode(&result)
44+
// if err != nil { log.Fatal(err) }
45+
// // do something with result...
46+
//
47+
// // To get the raw bson bytes use cursor.Current
48+
// raw := cur.Current
49+
// // do something with raw...
4150
// }
4251
// if err := cur.Err(); err != nil {
43-
// return err
52+
// return err
4453
// }
4554
//
4655
// Methods that only return a single document will return a *SingleResult, which works

0 commit comments

Comments
 (0)