Using Javascript to open pull replicators

I’m not sure this belongs in the Node.js SDK section as I don’t see that the SDK will help me here, but maybe someone can point out how it can.

My problem is that I want to open a pull replicator from a Javascript application. I know I can use the native Couchbase API to accomplish this, but I was hoping that there was an existing Node package that would assist with this process. I found this page which gives some advice for creating replications, but they don’t have a code example for Javascript. I guess the main issue is that there is no Couchbase Lite for Javascript right now.

Is there an approved or standard Node package that can help with creating and managing replications? Or alternatively are there any pages in the guide that I missed that cover some of the basics for manually creating replications from a Javascript application?

Thanks for taking a look at my question!

As you say, the issue is there’s no Couchbase Lite for Javascript right now.

For Node, I’d suggest either using the REST API (with Swagger, see this post), or using PouchDB.

Replication doesn’t make sense without a local store, which would point toward using PouchDB. That brings up the question of whether you really need the data local, or if the REST API suites your scenario. Can you describe your use? We’re trying to understand how to prioritize a JS version, so feedback on what you’re doing would be valuable.

Thanks for replying, Hod!

I’ll try and give you an idea of what we’re trying to accomplish. We already have Couchbase Lite running in a mobile environment which connects to Couchbase Server. Users have access to a file which can be changed simultaneously using the Sync Gateway. At one point we wanted the ability for a User to copy one of these files. We accomplished this by opening a one-shot pull replicator, getting all the data, creating a new database and then entering the documents back into the new database thus generating a reasonable copy.

We now want users to be able to perform the same copy from a Javascript application. So although they can’t view or manipulate the file in any way (since we weren’t planning on having any local datastore for this), they can choose to make a copy and access the copy from the mobile application.

Is this enough for you to go on or can I clarify any points?

Thanks again for your help on this!

Couldn’t the mobile app just use a regular XHR to GET the documents it needs?

Hi Jens,

The mobile application is not where the issue lies. From the mobile app, we can use Couchbase Lite to open Replicators and perform any actions we want.

The Javascript application is where we need to be able to pull the contents of a file from Couchbase Server, and then dump the contents into back in with a new ID thereby creating a copy of the original file. Although I think we will be able to use a regular Http request to get the documents back as you have suggested. Is there any documentation on how this would be setup? I’m a bit confused on which calls I would be using to accomplish this since I usually rely on the Couchbase Lite SDK to handle all of this for me.

Thanks!

Look at the docs on the Sync Gateway REST API, specifically GET and PUT of documents.