Sync
public class Sync<DocumentT> where DocumentT : Decodable, DocumentT : Encodable
Sync is a set of synchronization-related operations for a RemoteMongoCollection.
Using Sync, you can synchronize local and remote data.
See also
Build a Mobile App with Sync, RemoteMongoCollection-
Set the conflict resolver and and change event listener on this collection.
Declaration
Swift
public func configure( conflictHandler: @escaping ( _ documentId: BSONValue, _ localEvent: ChangeEvent<DocumentT>, _ remoteEvent: ChangeEvent<DocumentT>) throws -> DocumentT?, changeEventDelegate: ((_ documentId: BSONValue, _ event: ChangeEvent<DocumentT>) -> Void)? = nil, errorListener: ((_ error: DataSynchronizerError, _ documentId: BSONValue?) -> Void)? = nil, _ completionHandler: @escaping (StitchResult<Void>) -> Void)Parameters
conflictHandlerthe conflict resolver to invoke when a conflict happens between local and remote events.
changeEventDelegatethe event listener to invoke when a change event happens for the document.
errorListenerthe error listener to invoke when an irrecoverable error occurs
completionHandlerthe handler to execute when configuration is complete
-
Set the conflict resolver and and change event listener on this collection.
Declaration
Swift
public func configure<CH: ConflictHandler, CED: ChangeEventDelegate>( conflictHandler: CH, changeEventDelegate: CED? = nil, errorListener: ErrorListener? = nil, _ completionHandler: @escaping (StitchResult<Void>) -> Void ) where CH.DocumentT == DocumentT, CED.DocumentT == DocumentTParameters
conflictHandlerthe conflict resolver to invoke when a conflict happens between local and remote events.
changeEventDelegatethe event listener to invoke when a change event happens for the document.
errorListenerthe error listener to invoke when an irrecoverable error occurs
completionHandlerthe handler to execute when configuration is complete
-
Requests that the given document _ids be synchronized.
Declaration
Swift
public func sync(ids: [BSONValue], _ completionHandler: @escaping (StitchResult<Void>) -> Void)Parameters
idsthe document _ids to synchronize.
completionHandlerthe handler to execute when the provided ids are marked as synced. The documents will not necessarily exist in the local collection yet, but will get synced down in the next background sync pass
-
Stops synchronizing the given document _ids. Any uncommitted writes will be lost.
Declaration
Swift
public func desync(ids: [BSONValue], _ completionHandler: @escaping (StitchResult<Void>) -> Void)Parameters
idsthe _ids of the documents to desynchronize.
completionHandlerthe handler to execute when the provided ids are no longer marked as synced. The documents will be deleted from the local collection, but not the remote collection.
-
Returns the set of synchronized document ids in a namespace. Remove custom AnyBSONValue after: https://jira.mongodb.org/browse/SWIFT-255
Declaration
Swift
public func syncedIds(_ completionHandler: @escaping (StitchResult<Set<AnyBSONValue>>) -> Void)Return Value
the set of synchronized document ids in a namespace.
-
Return the set of synchronized document _ids in a namespace that have been paused due to an irrecoverable error.
Declaration
Swift
public func pausedIds(_ completionHandler: @escaping (StitchResult<Set<AnyBSONValue>>) -> Void)Return Value
the set of paused document _ids in a namespace
-
A document that is paused no longer has remote updates applied to it. Any local updates to this document cause it to be resumed. An example of pausing a document is when a conflict is being resolved for that document and the handler throws an exception.
Declaration
Swift
public func resumeSync( forDocumentId documentId: BSONValue, _ completionHandler: @escaping (StitchResult<Bool>) -> Void)Parameters
documentIdthe id of the document to resume syncing
Return Value
true if successfully resumed, false if the document could not be found or there was an error resuming
-
Counts the number of documents in the collection that have been synchronized with the remote.
Declaration
Swift
func count(_ completionHandler: @escaping (StitchResult<Int>) -> Void)Return Value
the number of documents in the collection
-
Counts the number of documents in the collection that have been synchronized with the remote according to the given options.
Declaration
Swift
func count(filter: Document, options: SyncCountOptions?, _ completionHandler: @escaping (StitchResult<Int>) -> Void)Parameters
filterthe query filter
optionsthe options describing the count
completionHandlerthe callback for the count result
Return Value
the number of documents in the collection
-
Finds all documents in the collection that have been synchronized with the remote.
Declaration
Swift
func find(_ completionHandler: @escaping (StitchResult<MongoCursor<DocumentT>>) -> Void)Parameters
completionHandlerthe callback for the find result
Return Value
the find iterable interface
-
Finds all documents in the collection that have been synchronized with the remote.
Declaration
Swift
func find( filter: Document, options: SyncFindOptions? = nil, _ completionHandler: @escaping (StitchResult<MongoCursor<DocumentT>>) -> Void)Parameters
filterthe query filter for this find op
optionsthe options for this find op
completionHandlerthe callback for the find result
Return Value
the find iterable interface
-
Finds a document in the collection that has been synchronized with the remote.
Declaration
Swift
func findOne( filter: Document? = nil, options: SyncFindOptions? = nil, _ completionHandler: @escaping (StitchResult<DocumentT?>) -> Void)Parameters
filterthe query filter for this find op
optionsthe options for this find op
completionHandlerthe callback for the find result
Return Value
the document or nil if no such document existss
-
Aggregates documents that have been synchronized with the remote according to the specified aggregation pipeline.
Declaration
Swift
func aggregate(pipeline: [Document], options: AggregateOptions?, _ completionHandler: @escaping (StitchResult<MongoCursor<Document>>) -> Void)Parameters
pipelinethe aggregation pipeline
optionsthe options for this aggregate op
Return Value
an iterable containing the result of the aggregation operation
-
Inserts the provided document. If the document is missing an identifier, the client should generate one. Syncs the newly inserted document against the remote.
Declaration
Swift
func insertOne(document: DocumentT, _ completionHandler: @escaping (StitchResult<SyncInsertOneResult?>) -> Void)Parameters
documentthe document to insert
Return Value
the result of the insert one operation
-
Inserts one or more documents. Syncs the newly inserted documents against the remote.
Declaration
Swift
func insertMany(documents: [DocumentT], _ completionHandler: @escaping (StitchResult<SyncInsertManyResult?>) -> Void)Parameters
documentsthe documents to insert
Return Value
the result of the insert many operation
-
Removes at most one document from the collection that has been synchronized with the remote that matches the given filter. If no documents match, the collection is not modified.
Declaration
Swift
func deleteOne(filter: Document, _ completionHandler: @escaping (StitchResult<SyncDeleteResult?>) -> Void)Parameters
filterthe query filter to apply the the delete operation
Return Value
the result of the remove one operation
-
Removes all documents from the collection that have been synchronized with the remote that match the given query filter. If no documents match, the collection is not modified.
Declaration
Swift
func deleteMany(filter: Document, _ completionHandler: @escaping (StitchResult<SyncDeleteResult?>) -> Void)Parameters
filterthe query filter to apply the the delete operation
Return Value
the result of the remove many operation
-
Update a single document in the collection that have been synchronized with the remote according to the specified arguments. If the update results in an upsert, the newly upserted document will automatically become synchronized.
Declaration
Swift
func updateOne(filter: Document, update: Document, options: SyncUpdateOptions?, _ completionHandler: @escaping (StitchResult<SyncUpdateResult?>) -> Void)Parameters
filtera document describing the query filter, which may not be null.
updatea document describing the update, which may not be null. The update to apply must include only update operators.
Return Value
the result of the update one operation
-
Update all documents in the collection that have been synchronized with the remote according to the specified arguments. If the update results in an upsert, the newly upserted document will automatically become synchronized.
Declaration
Swift
func updateMany(filter: Document, update: Document, options: SyncUpdateOptions?, _ completionHandler: @escaping (StitchResult<SyncUpdateResult?>) -> Void)Parameters
filtera document describing the query filter, which may not be null.
updatea document describing the update, which may not be null. The update to apply must include only update operators.
updateOptionsthe options to apply to the update operation
Return Value
the result of the update many operation
Sync Class Reference