FindOptions
public struct FindOptions : Codable
Options to use when executing a find
command on a MongoCollection
.
-
Enables the server to write to temporary files. When set to true, the find operation can write data to the _tmp subdirectory in the dbPath directory. This helps prevent out-of-memory failures server side when working with large result sets.
Note
This option is only supported in MongoDB 4.4+. Specifying it against earlier versions of the server will result in an error.Declaration
Swift
public var allowDiskUse: Bool?
-
Get partial results from a mongos if some shards are down (instead of throwing an error).
Declaration
Swift
public var allowPartialResults: Bool?
-
The number of documents to return per batch.
Declaration
Swift
public var batchSize: Int?
-
Specifies a collation.
Declaration
Swift
public var collation: BSONDocument?
-
Attaches a comment to the query.
Declaration
Swift
public var comment: String?
-
Indicates the type of cursor to use. This value includes both the tailable and awaitData options.
Declaration
Swift
public var cursorType: MongoCursorType? { get set }
-
A hint for the index to use.
Declaration
Swift
public var hint: IndexHint?
-
Variables that can be accessed within the operation using the double dollar sign prefix in the form
$$<variable_name>
. This option is only available on MongoDB 5.0+.Declaration
Swift
public var `let`: BSONDocument?
-
The maximum number of documents to return.
Declaration
Swift
public var limit: Int?
-
The exclusive upper bound for a specific index.
Declaration
Swift
public var max: BSONDocument?
-
The maximum amount of time, in milliseconds, for the server to wait on new documents to satisfy a tailable cursor query. This only applies when used with
MongoCursorType.tailableAwait
. Otherwise, this option is ignored.Declaration
Swift
public var maxAwaitTimeMS: Int?
-
The maximum amount of time to allow the query to run.
Declaration
Swift
public var maxTimeMS: Int?
-
The inclusive lower bound for a specific index.
Declaration
Swift
public var min: BSONDocument?
-
The server normally times out idle cursors after an inactivity period (10 minutes) to prevent excess memory use. Set this option to prevent that.
Declaration
Swift
public var noCursorTimeout: Bool?
-
Limits the fields to return for all matching documents.
Declaration
Swift
public var projection: BSONDocument?
-
A ReadConcern to use for this operation.
Declaration
Swift
public var readConcern: ReadConcern?
-
A ReadPreference to use for this operation.
Declaration
Swift
public var readPreference: ReadPreference?
-
If true, returns only the index keys in the resulting documents.
Declaration
Swift
public var returnKey: Bool?
-
Determines whether to return the record identifier for each document. If true, adds a field $recordId to the returned documents.
Declaration
Swift
public var showRecordID: Bool?
-
The number of documents to skip before returning.
Declaration
Swift
public var skip: Int?
-
The order in which to return matching documents.
Declaration
Swift
public var sort: BSONDocument?
-
init(allowDiskUse:
allowPartialResults: batchSize: collation: comment: cursorType: hint: let: limit: max: maxAwaitTimeMS: maxTimeMS: min: noCursorTimeout: projection: readConcern: readPreference: returnKey: showRecordID: skip: sort: ) Convenience initializer allowing any/all parameters to be omitted or optional.
Declaration
Swift
public init( allowDiskUse: Bool? = nil, allowPartialResults: Bool? = nil, batchSize: Int? = nil, collation: BSONDocument? = nil, comment: String? = nil, cursorType: MongoCursorType? = nil, hint: IndexHint? = nil, `let`: BSONDocument? = nil, limit: Int? = nil, max: BSONDocument? = nil, maxAwaitTimeMS: Int? = nil, maxTimeMS: Int? = nil, min: BSONDocument? = nil, noCursorTimeout: Bool? = nil, projection: BSONDocument? = nil, readConcern: ReadConcern? = nil, readPreference: ReadPreference? = nil, returnKey: Bool? = nil, showRecordID: Bool? = nil, skip: Int? = nil, sort: BSONDocument? = nil )