synchronizing pouchDB with json data

荒凉一梦 提交于 2019-12-23 15:14:06

问题


I want to create a html page which synchronize JSON data with pouch Db. The JSON data is a response from a web service.I have created a sample html file which can create a pouch Db database.I have created rest web service which gives certain data as response. can any one help me to synchronize these two.


回答1:


PouchDB has a built in method for synchronizing with CouchDB using one- or two-way replication.

I understand that you want to sync with a datasource, which doesn't have a CouchDB compatible API. Then you'll have to write code to perform the synchronization with your specific JSON API.




回答2:


There's a library now which makes it possible to import a JSON string (dump) as database into PouchDB.

It's called PouchDB-Load and is written by PouchDB author Nolan Lawson.

So in your case the code can be as simple as:

var db = new PouchDB('my-awesome-db'); db.load('http://example.com/my-dump-file.json').then(function () { // done loading! }).catch(function (err) { // HTTP error or something like that });



来源:https://stackoverflow.com/questions/21136107/synchronizing-pouchdb-with-json-data

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!