Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is creating multiple PouchDB databases on the same application considered bad design?

Tags:

nosql

pouchdb

I come from a Mysql background and I'm using Pouchdb now. I'm used to the SQL pattern of having 1 database and many tables per app.

In pouchDB it's different, because data is not stored in tables but in documents. So, in my app, I have a database for tasks, created with:

var db = new PouchDB('tasks', {revs_limit: 1, auto_compaction: true});

This is the main database for my application, but now I need to also store settings, such as "last_visit_date", "language_preference" and others.


So, I have 2 questions:

  1. Should I create only one database and then store different data
    sets in sub objects or can I create multiple databases to store this data Are there any drawbacks on the second option?
  2. I haven't gotten into syncing with cloudant or couchdb yet, but I will have to in the future. If I have 2 databases (or more) will it make the sync process more complicated, slower or worse somehow?
like image 455
sigmaxf Avatar asked Apr 18 '17 04:04

sigmaxf


1 Answers

Is creating multiple PouchDB databases on the same application considered bad design?

In a word: No.

Long answer: Databases in CouchDB/PouchDB are essentially free. And some application designs require multiple databases.

Consider a theoretical Offline-first/mobile app which tracks an agent's sales. It may have a database for inventory management purposes, which is synchronized with a central CouchDB server.

It will likely also have a per-agent database, with client and sales info for a given agent.

The PouchDB app will need both databases. And due to the design of CouchDB, there's no (easy, sane) way to keep those data sets in the same database, and keep agent's records separate from each other.

Databases in CouchDB/PouchDB are more like tables than databases in an RDBMS.

The only real limiting factor for creating additional databases in PouchDB (which doesn't apply to CouchDB), is that there's no easy way to list your existing databases, except with the use of plugin. This needn't be a real limitation--it just means you need to remember which databases you've created (you probably shouldn't be programatically creating randomly-named databases... but that would probably be a bad design anyway. ;-) )

like image 151
Flimzy Avatar answered Nov 20 '22 13:11

Flimzy