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
Codable
type associated with thisMongoCollection
instance. This allowsCollectionType
values to be directly inserted into and retrieved from the collection, by encoding/decoding them using theBsonEncoder
andBsonDecoder
. This type association only exists in the context of this particularMongoCollection
instance. 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
Codable
type 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
RemoteMongoReadOperation
instance to trigger the operation against the database.Declaration
Swift
public func find(_ filter: Document = [:], options: RemoteFindOptions? = nil) -> RemoteMongoReadOperation<CollectionType>
Parameters
filter
A
Document
that should match the query.options
Optional
RemoteFindOptions
to use when executing the command.Return Value
A
RemoteMongoReadOperation
that allows retrieval of the resulting documents. -
Runs an aggregation framework pipeline against this collection.
Declaration
Swift
public func aggregate(_ pipeline: [Document]) -> RemoteMongoReadOperation<CollectionType>
Parameters
pipeline
An
[Document]
containing the pipeline of aggregation operations to perform.important
Invoking this method by itself does not perform any network requests. You must call one of the methods on the resulting
RemoteMongoReadOperation
instance to trigger the operation against the database.Return Value
A
RemoteMongoReadOperation
that 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
filter
a
Document
, the filter that documents must match in order to be counted.options
Optional
RemoteCountOptions
to use when executing the command.completionHandler
The 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
value
A
CollectionType
value to encode and insert.completionHandler
The 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
documents
The
CollectionType
values to insert.completionHandler
The completion handler to call when the insert is completed or if the operation fails. This handler is executed on a non-main global
DispatchQueue
.result
The result of attempting to perform the insert, or
nil
if 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
filter
A
Document
representing the match criteria.completionHandler
The 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
filter
A
Document
representing the match criteria.completionHandler
The 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
filter
A
Document
representing the match criteria.update
A
Document
representing the update to be applied to a matching document.options
Optional
RemoteUpdateOptions
to use when executing the command.completionHandler
The 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
filter
A
Document
representing the match criteria.update
A
Document
representing the update to be applied to a matching document.options
Optional
RemoteUpdateOptions
to use when executing the command.completionHandler
The 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
.