func (c *Cursor) All(ctx context.Context, results interface{}) error {
	resultsVal := reflect.ValueOf(results)
	if resultsVal.Kind() != reflect.Ptr {
		return fmt.Errorf("results argument must be a pointer to a slice, but was a %s", resultsVal.Kind())
	}
	sliceVal := resultsVal.Elem()
	if sliceVal.Kind() == reflect.Interface {
		sliceVal = sliceVal.Elem()
	}
	if sliceVal.Kind() != reflect.Slice {
		return fmt.Errorf("results argument must be a pointer to a slice, but was a pointer to %s", sliceVal.Kind())
	}
	elementType := sliceVal.Type().Elem()
	var index int
	var err error
	defer c.Close(ctx)
	batch := c.batch  
	for {
		sliceVal, index, err = c.addFromBatch(sliceVal, elementType, batch, index)
		if err != nil {
			return err
		}
		if !c.bc.Next(ctx) {
			break
		}
		batch = c.bc.Batch()
	}
	if err = replaceErrors(c.bc.Err()); err != nil {
		return err
	}
	resultsVal.Elem().Set(sliceVal.Slice(0, index))
	return nil
}
All iterates the cursor and decodes each document into results. The results parameter must be a pointer to a slice.
The slice pointed to by results will be completely overwritten. This method will close the cursor after retrieving
all documents. If the cursor has been iterated, any previously iterated documents will not be included in results.

This method requires driver version >= 1.1.0.
package mongo
import (
	"context"
	"errors"
	"fmt"
	"io"
	"reflect"
	"go.mongodb.org/mongo-driver/bson"
	"go.mongodb.org/mongo-driver/bson/bsoncodec"
	"go.mongodb.org/mongo-driver/x/bsonx/bsoncore"
	"go.mongodb.org/mongo-driver/x/mongo/driver"
	"go.mongodb.org/mongo-driver/x/mongo/driver/session"
)
type Cursor struct {
	Current bson.Raw
	bc            batchCursor
	batch         *bsoncore.DocumentSequence
	batchLength   int
	registry      *bsoncodec.Registry
	clientSession *session.Client
	err error
}
func newCursor(bc batchCursor, registry *bsoncodec.Registry) (*Cursor, error) {
	return newCursorWithSession(bc, registry, nil)
}
func newCursorWithSession(bc batchCursor, registry *bsoncodec.Registry, clientSession *session.Client) (*Cursor, error) {
	if registry == nil {
		registry = bson.DefaultRegistry
	}
	if bc == nil {
		return nil, errors.New("batch cursor must not be nil")
	}
	c := &Cursor{
		bc:            bc,
		registry:      registry,
		clientSession: clientSession,
	}
	if bc.ID() == 0 {
		c.closeImplicitSession()
	}
	c.batchLength = c.bc.Batch().DocumentCount()
	return c, nil
}
func newEmptyCursor() *Cursor {
	return &Cursor{bc: driver.NewEmptyBatchCursor()}
}
func (c *Cursor) ID() int64 { return c.bc.ID() }
func (c *Cursor) Next(ctx context.Context) bool {
	return c.next(ctx, false)
}
func (c *Cursor) TryNext(ctx context.Context) bool {
	return c.next(ctx, true)
}
func (c *Cursor) next(ctx context.Context, nonBlocking bool) bool {
	if c.err != nil {
		return false
	}
	if ctx == nil {
		ctx = context.Background()
	}
	doc, err := c.batch.Next()
	switch err {
	case nil:
		c.batchLength--
		c.Current = bson.Raw(doc)
		return true
	case io.EOF:  
	default:
		c.err = err
		return false
	}
	for {
		if !c.bc.Next(ctx) {
			c.err = replaceErrors(c.bc.Err())
			if c.err != nil {
				return false
			}
			if c.bc.ID() == 0 {
				c.closeImplicitSession()
				return false
			}
			if nonBlocking {
				return false
			}
			continue
		}
		if c.bc.ID() == 0 {
			c.closeImplicitSession()
		}
		c.batch = c.bc.Batch()
		c.batchLength = c.batch.DocumentCount()
		doc, err = c.batch.Next()
		switch err {
		case nil:
			c.batchLength--
			c.Current = bson.Raw(doc)
			return true
		case io.EOF:  
		default:
			c.err = err
			return false
		}
	}
}
func (c *Cursor) Decode(val interface{}) error {
	return bson.UnmarshalWithRegistry(c.registry, c.Current, val)
}
func (c *Cursor) Err() error { return c.err }
func (c *Cursor) Close(ctx context.Context) error {
	defer c.closeImplicitSession()
	return replaceErrors(c.bc.Close(ctx))
}