Skip to content

Instantly share code, notes, and snippets.



Last active Aug 29, 2015
What would you like to do?
FAQ for LoopBack replication

Will it be possible to use continuous replication, so the client immediately triggers a replication when local data changes. And the server uses a push mechanism?

Yes... here is a basic example that relies on a style EventEmitter.

// psuedo-server.js
MyModel.on('changed', function(obj) {

// psuedo-client.js
socket.on('changed', function(obj) {

Is it possible to trigger immediate replication?

Yes. Calling Model.replicate() will trigger an immediate replication.

How are conflicts handled (e.g. an object or field is modified both locally and remotely)?

A conflict occurs when a change to a model is not based on the previous revision of the model.

The callback of Model.replicate() takes err and conflict[]. Each conflict represents a change that was not replicated and must be manually resolved. You can fetch the current versions of the local and remote models by calling conflict.models(). You can manaully merge the conflict by modifying both models. Calling conflict.resolve() will set the source change's previous revision to the current revision of the (conflicting) target change. Since the changes are no longer conflicting and appear as if the source change was based on the target, they will be replicated normally as part of the next replicate() call.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.