Exciting Features in CouchDB
The deeper I get into CouchDB, the more I love it. I empathize with the thread on Quora about why isn’t couchDB more popular? started by someone who was blown away like I was when I started using CouchDB.
Quick FYI: this article is a high-level overview of CouchDB features, not a tutorial.
If you are a web application developer, you know your apps just end up being a REST interface to SQL queries that check a session for permission. I can’t tell you how many times I see application that are just mapping SQL queries to a router of some sort. Welp, no need for that if you use CouchDB (albeit it takes a lot of learning to get there).
CouchDB is HTTP / REST-based in its core.
Here is an overview of more features that make me happy using CouchDB.
Play with your data, permissions and configuration right from the browser with CouchDB’s interface Futon.
I’ve never seen a database so simple to replicate. Just make a POST request.
And your database is replicated for you. You can even add
"continuous": true and your database will sync automatically. You can also add filters to your replication to only sync certain types of data.
JSONP for Free
Update your config to allow_jsonp = true and BAM! Automatically your database is accessible cross domain for GET requests. There an even a code commit recently to add support for full cross-domain XHR in CouchDB.
Want to know if your database has been changed and update the UI accordingly? You can open a HTTP socket to /db/_changes?continuous=true and be notified as changes occur in the database. You can even apply filters to only listen for certain types of changes.
Authentication and Session Support
The Authentication features in CouchDB has certainly blown me away multiple times. Not only can you login via basic HTTP Authentication http://username:password@yourdatabase, but you can also keep authentication open via a session cookie. Ok, so we have been doing this in web applications for ever, but this is a database. POST username and password to _session and you get a cookie. =)
It also has database-level security. The permissions per database are separated into readers and admins. Readers can both read and write to the database so I think they are changing the name of that, but admins can also update the _design documents in a database…you don’t want normal users to be able to do that.
Combine auth / session handling with security and you now can allow your normal users to access your database directly from the browser!
The ability to validate inserts is built right into the database. You can combine with authentication to check to make sure the creator of the document is the one who is logged in.
CouchDB supports OAuth out of the box too, so if you want to persist your authentication you get that for free too.
Map/Reduce, List and Show
Of course the most difficult hurdle to leap into CouchDB and why so many people just jump into MongoDB is the map/reduce system. You have to learn how to take a bunch of documents, emit what you need and then reduce it down based on grouping relevant data. At that point you use _list and _show methods to get whatever you need from the aggregated data.
But be forewarned…being able to map/reduce and then filter on a dataset with views takes a while to wrap your head around.
You can attach blobs to a document and serve them directly out of CouchDB. With attachments you can serve out entire web applications with CouchDB.
Cool Projects in CouchDB Ecosystem
iOS Couchbase lets you package a local CouchDB in an iOS app. This really takes advantage of Couch’s replication and the philosophy of the project.
Geospacial indexing here we go, with GeoCouch
Need to split up your CouchDB across multiple servers? Use Lounge Nginx module
Not 100% Roses
Meets My Needs