1 // Copyright (C) MongoDB, Inc. 2022-present. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); you may 4 // not use this file except in compliance with the License. You may obtain 5 // a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 6 7 package mongo 8 9 import ( 10 "context" 11 "time" 12 13 "go.mongodb.org/mongo-driver/x/bsonx/bsoncore" 14 "go.mongodb.org/mongo-driver/x/mongo/driver" 15 ) 16 17 // batchCursor is the interface implemented by types that can provide batches of document results. 18 // The Cursor type is built on top of this type. 19 type batchCursor interface { 20 // ID returns the ID of the cursor. 21 ID() int64 22 23 // Next returns true if there is a batch available. 24 Next(context.Context) bool 25 26 // Batch will return a DocumentSequence for the current batch of documents. The returned 27 // DocumentSequence is only valid until the next call to Next or Close. 28 Batch() *bsoncore.DocumentSequence 29 30 // Server returns a pointer to the cursor's server. 31 Server() driver.Server 32 33 // Err returns the last error encountered. 34 Err() error 35 36 // Close closes the cursor. 37 Close(context.Context) error 38 39 // SetBatchSize is a modifier function used to adjust the batch size of 40 // the cursor that implements it. 41 SetBatchSize(int32) 42 43 // SetMaxTime will set the maximum amount of time the server will allow 44 // the operations to execute. The server will error if this field is set 45 // but the cursor is not configured with awaitData=true. 46 // 47 // The time.Duration value passed by this setter will be converted and 48 // rounded down to the nearest millisecond. 49 SetMaxTime(time.Duration) 50 51 // SetComment will set a user-configurable comment that can be used to 52 // identify the operation in server logs. 53 SetComment(interface{}) 54 } 55 56 // changeStreamCursor is the interface implemented by batch cursors that also provide the functionality for retrieving 57 // a postBatchResumeToken from commands and allows for the cursor to be killed rather than closed 58 type changeStreamCursor interface { 59 batchCursor 60 // PostBatchResumeToken returns the latest seen post batch resume token. 61 PostBatchResumeToken() bsoncore.Document 62 63 // KillCursor kills cursor on server without closing batch cursor 64 KillCursor(context.Context) error 65 } 66