CouchDB is my personal BaaS
The projects I am talking are my personal GPS logger which logs the locations while I am travelling. Couple of small IoT devices, a weather station, data I collect as part of quantified self etc. They are not very complex in terms of data structure. But they need a flexible, stable and simple system.
A simple Backend-as-a-Service platform is what I wanted. Something that was open source and can be hosted by me easily. So Firebase and other similar services got excluded easily. Open Source BaaS has many choices Meteor, Hook , Hoodie, etc. They are all good choices. Some of them are even built on the top of CouchDB. But I choose CouchDB over others for a bunch of reasons.
- NoSQL- It's a simple versioned document store. You put the JSON and You get the JSON back. Just like in any other NoSQL its schema-less.
- Restful API You access database through restful API. Thats the primary way to get access to the database. Since its restful, you can interact with the database direct from browser or mobile.
- Replication synchronizes two copies of the same database and works really well.
- Simple JSONP is part of CouchDB. If you want to just access the data. You could use this.
- Futon UI is a native web-based interface built into CouchDB. Its like PHPMyAdmin but much better UI and it comes by default.
- Media Attachments can be stored on CouchDB. Even though it's not advised to use it as a file storage, the fact that it can store BLOBs makes it useful in certain situations.
- CouchDB has built-in support for Auth and Sessions. You can use the same RESTFUL api to create a web-session. Basically POST username and password to _session and you will receive a cookie. You can use this cookie for all the future transactions. You can also use simple https://username:email@example.com/mydatabase if that suits your taste.
- Users can write Validation functions on couchdb. This can be used to validate the documents while inserting or updating.
- All the views are MapReduce. You have to write MapReduce to query the database.
- All these features are one single installation. And everything happens over http (i prefer https). It makes the system simple, secure and stable.
As of now I use hosted service by IBM called Cloudant. I also have a locally installed Apache CouchDB. Local version gets synced with cloudant once in a while (one way). This works as backup.
In the next set of blog posts I will write about my use-cases and projects. In the mean time let me know what you think.
Imagine this setup for Node/Express/Vue project :
– desktop app (Electron) : writes to PouchDB (offline first) with a possibility to sync with remote db.
– web app (online) : uses API server calls to write to CouchDB
– PouchDB is on client
– CouchDB is on server
These two use the same data and I know I can sync (master-master db) them.
I’m wondering how I would manage the code to achieve this.
1. Is it possible to use the same controllers/models to interact with both databases?
2. Or would I have to write controllers/models on the server to interact with CouchDB and also write other controllers/models on the client to interact with PouchDB?
3. How would you structure a project like that ?
Thank you to clarify this, as I can’t seem to find a clear answer for this and I’m a total noob.