ReadOnly sync

142 views
Skip to first unread message

Raymond Camden

unread,
Jun 5, 2015, 10:05:55 AM6/5/15
to pou...@googlegroups.com
Is it possible to use PouchDB so that sync only comes from the server to the client? In other words, I want the ability to easily sync from the server, but anything on the client should be considered trash/dispensable/etc. As a real world example of this - imagine a game/app with text based documentation. I want to store these docs on the server but give the client easy access to them. I will never need to check the client for new docs.

Nolan Lawson

unread,
Jun 5, 2015, 10:24:35 AM6/5/15
to pou...@googlegroups.com, raymon...@gmail.com
Hey Raymond,

There are a couple ways you could do it:

1) Configure your CouchDB database so that everybody has read access, but only admins have write access. This is described in the pouchdb-authentication docs [1]. Then to do a one-way replication, you just use db.replicate.from() instead of db.sync().

2) Or if performance is critical, and if your data doesn't change very often, use pouchdb-dump-cli [2] to dump to a file, then use pouchdb-load [3] to load that file on the client.

I've sometimes done a mixed approach. E.g. with the npm-browser app [4], I start off using pouchdb-load to pull documents from Amazon S3, then after that's done, I switch to regular replication from a read-only Couch, which is rendered read-only by this very simple design document: http://skimdb.iriscouch.com/registry/_design/validate

Note that the authentication becomes a bit different if you are using Cloudant/Couchbase, because their authentication scheme differs from CouchDB's.

Hope that helps!

- Nolan

[1]: https://github.com/nolanlawson/pouchdb-authentication#everybody-can-read-only-some-can-write-everything
[2]: https://github.com/nolanlawson/pouchdb-dump-cli
[3]: https://github.com/nolanlawson/pouchdb-load
[4]: http://npm-browser.com

Raymond Camden

unread,
Jun 5, 2015, 11:19:40 AM6/5/15
to pou...@googlegroups.com, raymon...@gmail.com
Thank you!


On Friday, June 5, 2015 at 9:24:35 AM UTC-5, Nolan Lawson wrote:
Hey Raymond,

There are a couple ways you could do it:



-
Reply all
Reply to author
Forward
0 new messages