Skip to content

Commit 3273f8e

Browse files
committed
Added more documentation to the cursor access functions
1 parent 612b5a2 commit 3273f8e

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

cursor.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,9 @@ func (c *Cursor) Close() error {
116116
// and false at the end of the result set or if an error happened.
117117
// When Next returns false, the Err method should be called to verify if
118118
// there was an error during iteration.
119+
//
120+
// Also note that you are able to reuse the same variable multiple times as
121+
// `Next` zeroes the value before scanning in the result.
119122
func (c *Cursor) Next(dest interface{}) bool {
120123
if c.closed {
121124
return false
@@ -197,6 +200,11 @@ func (c *Cursor) loadNext(dest interface{}) (bool, error) {
197200
//
198201
// The result argument must necessarily be the address for a slice. The slice
199202
// may be nil or previously allocated.
203+
//
204+
// Also note that you are able to reuse the same variable multiple times as
205+
// `All` zeroes the value before scanning in the result. It also attempts
206+
// to reuse the existing slice without allocating any more space by either
207+
// resizing or returning a selection of the slice if necessary.
200208
func (c *Cursor) All(result interface{}) error {
201209
resultv := reflect.ValueOf(result)
202210
if resultv.Kind() != reflect.Ptr || resultv.Elem().Kind() != reflect.Slice {
@@ -237,6 +245,9 @@ func (c *Cursor) All(result interface{}) error {
237245

238246
// One retrieves a single document from the result set into the provided
239247
// slice and closes the cursor.
248+
//
249+
// Also note that you are able to reuse the same variable multiple times as
250+
// `One` zeroes the value before scanning in the result.
240251
func (c *Cursor) One(result interface{}) error {
241252
if c.IsNil() {
242253
return ErrEmptyResult

0 commit comments

Comments
 (0)