RemoteMongoCollection
public class RemoteMongoCollection<T> where T : Decodable, T : Encodable
A class representing a MongoDB collection accesible via the Stitch MongoDB service. Operations against the Stitch server are performed asynchronously.
-
The name of this collection.
Declaration
Swift
public var name: String { get } -
The name of the database containing this collection.
Declaration
Swift
public var databaseName: String { get }
-
A
Codabletype associated with thisMongoCollectioninstance. This allowsCollectionTypevalues to be directly inserted into and retrieved from the collection, by encoding/decoding them using theBsonEncoderandBsonDecoder. This type association only exists in the context of this particularMongoCollectioninstance. It is the responsibility of the user to ensure that any data already stored in the collection was encoded from this same type.Declaration
Swift
public typealias CollectionType = T -
Creates a collection using the same datatabase name and collection name, but with a new
Codabletype with which to encode and decode documents retrieved from and inserted into the collection.Declaration
Swift
public func withCollectionType<U>(_ type: U.Type) -> RemoteMongoCollection<U> where U : Decodable, U : Encodable
-
Finds the documents in this collection which match the provided filter.
Important
Invoking this method by itself does not perform any network requests. You must call one of the methods on the resulting
RemoteMongoReadOperationinstance to trigger the operation against the database.Declaration
Swift
public func find(_ filter: Document = [:], options: RemoteFindOptions? = nil) -> RemoteMongoReadOperation<CollectionType>Parameters
filterA
Documentthat should match the query.optionsOptional
RemoteFindOptionsto use when executing the command.Return Value
A
RemoteMongoReadOperationthat allows retrieval of the resulting documents. -
Runs an aggregation framework pipeline against this collection.
Declaration
Swift
public func aggregate(_ pipeline: [Document]) -> RemoteMongoReadOperation<CollectionType>Parameters
pipelineAn
[Document]containing the pipeline of aggregation operations to perform.importantInvoking this method by itself does not perform any network requests. You must call one of the methods on the resulting
RemoteMongoReadOperationinstance to trigger the operation against the database.Return Value
A
RemoteMongoReadOperationthat allows retrieval of the resulting documents. -
Counts the number of documents in this collection matching the provided filter.
Declaration
Swift
public func count(_ filter: Document = [:], options: RemoteCountOptions? = nil, _ completionHandler: @escaping (StitchResult<Int>) -> Void)Parameters
filtera
Document, the filter that documents must match in order to be counted.optionsOptional
RemoteCountOptionsto use when executing the command.completionHandlerThe completion handler to call when the count is completed or if the operation fails. This handler is executed on a non-main global
DispatchQueue. If the operation is successful, the result will contain the count of the documents that matched the filter. -
Encodes the provided value to BSON and inserts it. If the value is missing an identifier, one will be generated for it.
Important
If the insert failed due to a request timeout, it does not necessarily indicate that the insert failed on the database. Application code should handle timeout errors with the assumption that the document may or may not have been inserted.
Declaration
Swift
public func insertOne(_ value: CollectionType, _ completionHandler: @escaping (StitchResult<RemoteInsertOneResult>) -> Void)Parameters
valueA
CollectionTypevalue to encode and insert.completionHandlerThe completion handler to call when the insert is completed or if the operation fails. This handler is executed on a non-main global
DispatchQueue. If the operation is successful, the result will contain the result of attempting to perform the insert, as aRemoteInsertOneResult. -
Encodes the provided values to BSON and inserts them. If any values are missing identifiers, they will be generated.
Important
If the insert failed due to a request timeout, it does not necessarily indicate that the insert failed on the database. Application code should handle timeout errors with the assumption that documents may or may not have been inserted.
Declaration
Swift
public func insertMany(_ documents: [CollectionType], _ completionHandler: @escaping (StitchResult<RemoteInsertManyResult>) -> Void)Parameters
documentsThe
CollectionTypevalues to insert.completionHandlerThe completion handler to call when the insert is completed or if the operation fails. This handler is executed on a non-main global
DispatchQueue.resultThe result of attempting to perform the insert, or
nilif the insert failed. If the operation is successful, the result will contain the result of attempting to perform the insert, as aRemoteInsertManyResult. -
Deletes a single matching document from the collection.
Important
If the delete failed due to a request timeout, it does not necessarily indicate that the delete failed on the database. Application code should handle timeout errors with the assumption that a document may or may not have been deleted.
Declaration
Swift
public func deleteOne(_ filter: Document, _ completionHandler: @escaping (StitchResult<RemoteDeleteResult>) -> Void)Parameters
filterA
Documentrepresenting the match criteria.completionHandlerThe completion handler to call when the delete is completed or if the operation fails. This handler is executed on a non-main global
DispatchQueue. If the operation is successful, the result will contain the result of performing the deletion, as aRemoteDeleteResult. -
Deletes multiple documents from the collection.
Important
If the delete failed due to a request timeout, it does not necessarily indicate that the delete failed on the database. Application code should handle timeout errors with the assumption that documents may or may not have been deleted.
Declaration
Swift
public func deleteMany(_ filter: Document, _ completionHandler: @escaping (StitchResult<RemoteDeleteResult>) -> Void)Parameters
filterA
Documentrepresenting the match criteria.completionHandlerThe completion handler to call when the delete is completed or if the operation fails. This handler is executed on a non-main global
DispatchQueue. If the operation is successful, the result will contain the result of performing the deletion, as aRemoteDeleteResult. -
Updates a single document matching the provided filter in this collection.
Important
If the update failed due to a request timeout, it does not necessarily indicate that the update failed on the database. Application code should handle timeout errors with the assumption that a document may or may not have been updated.
Declaration
Swift
public func updateOne(filter: Document, update: Document, options: RemoteUpdateOptions? = nil, _ completionHandler: @escaping (StitchResult<RemoteUpdateResult>) -> Void)Parameters
filterA
Documentrepresenting the match criteria.updateA
Documentrepresenting the update to be applied to a matching document.optionsOptional
RemoteUpdateOptionsto use when executing the command.completionHandlerThe completion handler to call when the update is completed or if the operation fails. This handler is executed on a non-main global
DispatchQueue. If the operation is successful, the result will contain the result of attempting to update a document, as aRemoteUpdateResult. -
Updates mutiple documents matching the provided filter in this collection.
Important
If the update failed due to a request timeout, it does not necessarily indicate that the update failed on the database. Application code should handle timeout errors with the assumption that documents may or may not have been updated.
Declaration
Swift
public func updateMany(filter: Document, update: Document, options: RemoteUpdateOptions? = nil, _ completionHandler: @escaping (StitchResult<RemoteUpdateResult>) -> Void)Parameters
filterA
Documentrepresenting the match criteria.updateA
Documentrepresenting the update to be applied to a matching document.optionsOptional
RemoteUpdateOptionsto use when executing the command.completionHandlerThe completion handler to call when the update is completed or if the operation fails. This handler is executed on a non-main global
DispatchQueue. If the operation is successful, the result will contain the result of attempting to update multiple documents, as aRemoteUpdateResult.
RemoteMongoCollection Class Reference