Data Sync
here's a detailed guide with step by step instructions on integrating sync functionality within your app, allowing seamless communication with remote peers sync start and stop required only once, initiating the sync process automatically connects you with the mesh network once connected, you immediately begin receiving updates from publishing remote peers and sending updates to subscribing remote peers starting sync to start the sync process try! ditto startsync()try { ditto startsync() } catch (e dittoerror) { // handle error }try { ditto startsync() } catch (err) { // handle error }try { ditto startsync(); } catch(dittoerror e) { // handle error }try { ditto startsync(); } catch (dittoexception ex) { // handle exception }try { ditto start sync(); } catch (const dittoerror \&err) { std cerr << err what(); }ditto try start sync()?; ensure the sync process remains active throughout your app's lifecycle by starting the sync process ( startsync ) in the top most scope of your code stopping sync to stop the sync process, call the stopsync function once called, all active sync subscriptions end and you disconnect from the mesh try! ditto stopsync()try { ditto stopsync() } catch (e dittoerror) { // handle error }try { ditto stopsync() } catch (err) { // handle error }try { ditto stopsync(); } catch(dittoerror e) { // handle error }try { ditto stopsync(); } catch (dittoexception ex) { // handle exception }try { ditto stop sync(); } catch (const dittoerror \&err) { std cerr << err what(); }ditto try stop sync()?; subscriptions management dql sync subscriptions are supported for devices on version 4 5 or later devices on ditto versions 4 4 or earlier are supported, however will not sync data by way of dql subscriptions for information on syncing with devices on version 4 4 and earlier, see platform manual > legacy api & language > docid 4mf4vp9mk0wzc2colhflh manage your sync subscriptions to get your active subscriptions, call the subscriptions method on the ditto sync namespace ( /#retrieving subscriptions ) to cancel a subscription, call cancel on its subscription object you instantiated when setting up your subscription ( /#canceling subscriptions ) to confirm cancelation, call the iscancelled field on the subscription object ( /#canceling subscriptions ) creating subscriptions to register a new sync subscription in your app for example, the following snippet demonstrates how to establish a subscription to sync updates to documents in the cars collection with a field of color set to the value blue ditto sync registersubscription("select from cars")ditto sync registersubscription("select from cars")ditto sync registersubscription("select from cars")ditto sync registersubscription("select from cars")ditto sync registersubscription("select from cars");auto subscription = ditto sync() register subscription("select from cars");let subscription = ditto sync() register subscription("select from cars", none); sync subscriptions also support argument injection using the \ argument syntax in dql ditto sync registersubscription(""" select from cars where color = \ color """, \[ "color" "blue" ])ditto sync registersubscription(""" select from cars where color = \ color """, mapof("color" to "blue"))ditto sync registersubscription(` select from cars where color = \ color`, { color 'blue' })ditto sync registersubscription( "select from cars where color = \ color", collections singletonmap("color", "blue"))var queryarguments = new dictionary\<string, object>(){{"color", "blue" }}; ditto sync registersubscription( "select from cars where color = 'blue'", queryarguments);ditto sync() register subscription( "select from cars where color = \ color", {{"color", "blue"}});struct args { color string, } // let args = args { color "blue" to string(), }; ditto sync() register subscription( "select from cars where color = \ color", args); retrieving subscriptions retrieve active sync subscriptions by calling the subscriptions method on the ditto sync namespace let activesubscriptions = ditto sync subscriptions;val activesubscriptions = ditto sync subscriptionsconst activesubscriptions = ditto sync subscriptionsdittosyncsubscription\[] activesubscriptions = ditto sync subscriptions;var activesubscriptions = ditto sync subscriptions;// not supported hold the reference to the syncsubscription object // not supported hold the reference to the syncsubscription object canceling subscriptions to cancel a subscription, call cancel on the subscription object you set up to establish your subscription subscription cancel()subscription close()subscription cancel()subscription close()subscription cancel();// // you can check if a sync subscription is canceled by using the iscancelled field on the subscription object subscription iscancelledsubscription isclosedsubscription iscancelledsubscription iscancelledsubscription iscancelled// // attachments sync attachments are synced on demand using the attachment api methods syncing large documents can significantly impact sync performance be cautious handling very large binary data, a deeply embedded or very large document carefully consider using attachments instead of storing the data directly within a document object for more information, see docid\ vofl0gukxq8ajsmmw7sgz and docid\ ko44x97im4nop3qio9vyu