0


I'm currently working for a startup which ask me to develop an offline app using pouchDB. This pouchdb is used to store the data entered by users.
The offline application works fine. Now I have to add one feature on the online app to sync the dbs. After a login, the online app have to check if data is stored in a pouchdb on the device which is connecting, and, if the check found data, the online app have to pull this data.
I have the folowing problem: the online app can't get the db stored localy on the device (even if I run the both app in the same browser).

I explain my problem in another StackOverflow post, but the formulation was not so good so I think that's a good thing to post another question.

My old post here

I work on this problem during few days and I don't have much time until I have to finish my work, if someone know how to solve this, it could be very nice :)

1 Answer 1

2

I think the lack of response is because readers are not very clear what the problem is. In your other post it sounds like you are saying if you write a new entry to the local database you cannot retrieve it again. In this question it sounds like once you have a local database entry you cannot make it replicate to the server database - is that the case?

On the PouchDb front page is a short example of writing to a local database and then replicating it to a server. Like this:

var db = new PouchDB('dbname');

db.put({
  _id: '[email protected]',
  name: 'David',
  age: 69
});

db.replicate.to('http://example.com/mydb');

(the example assumes the database can be updated by anyone ie no security - otherwise you need a username and password as explained here)

Does this work for you? If not can you say what happens?

Checking to see if there is data locally should be a case of seeing if your local database has any entries in it (db.info would be a start as it returns a document count). Then you could replicate the local database using the db.replicate call.

Does this help?

Sign up to request clarification or add additional context in comments.

1 Comment

I think this is not the problem of TS, he is running his local offline pouchDB in a different host than his local online(the one that actually sync) pouchdb(for example localhost:3000 instead of localhost:9000). The problem with this is pouchDB stores the information based on both name + host. As otherwise you could easily run in name conflicts. So the problem is even though those two databases share the same name, the app that can connect to the internet uses a different db(but with the same name). As a result he is unable to sync the data of his offline db.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.