arnoutaertgeerts
arnoutaertgeerts

Reputation: 2322

PouchDB as a real live data tool for different collections

I'm thinking of using PouchDB as a solution to automatically update comments that are submitted by users on papers.

It should mimic the behavior of a subscribe/publish service. Whenever someone submits a comment in his client, the list of comments on an other client should automatically update.

This is possible using PouchDB as described in the getting started guide:

var db = new PouchDB('paper');
var remoteCouch = 'http://user:[email protected]/paper';

function sync() {      
  var opts = {live: true};
  db.replicate.to(remoteCouch, opts, syncError);
  db.replicate.from(remoteCouch, opts, syncError);
}

The app holds different papers, each with their own comments. When using PouchDB as my publish/subscribe service, I have these questions:

Upvotes: 3

Views: 1945

Answers (1)

nlawson
nlawson

Reputation: 11620

Yep, PouchDB works fine for real-time stuff. It doesn't use web sockets, but it uses long-polling, which is fast enough for most use cases.

It sounds like you probably should create a separate database for each paper, assuming you want to restrict access on a per-paper basis. CouchDB authentication is kinda tricky, but basically if you want to control read access, you can either give users full read access or zero read access to an entire database. There's a writeup here.

Also don't worry about creating thousands of databases; a "database" is cheap in CouchDB.

The only other thing I would advise is that maybe you would like the relational-pouch plugin, because then you could easily set up a relational-style database with a "paper" type and a "comment" type.

Upvotes: 3

Related Questions