Some of you know we are working with CouchDB quite intensively here at echolibre, and so I figured we might as well share a few of our notes, hickups, ideas, implementations, etc. So I decided to make a series of short post on CouchDB (>= 0.10.0) and I would like to start with writing your first CouchDB view in Erlang.
Obviously, you have to make sure that you enabled native Erlang views. Make sure to read on how to enabled your Erlang views on the CouchDB wiki
Once you are done, you can go into Futon and you should see “Erlang” in the list of available view languages:
Which is perfectly fine, however in Erlang it’s a bit different, if you want to use a field, you have to make sure it’s there.
For the purpose of this post and trying to keep it short, I’ve made a rather simple view with 2 functions (fun()). 1 to validate the fields are present in the document and 1 to emit what we need.
or the compacted version:
Go to Futon’s temp view editor, select language Erlang, paste the previous code, click on Save and save your view.
They should both return the same output and you now have your first Erlang view working
Note that if you want to have a reduce function, this map function has a major flaw. I’ll point it out with an explanation in the second post regarding CouchDB Map/Reduce functions
We like to blog about things we're passionate about. We love PHP, MySQL, CouchDB, Linux, Apache - web development standards. We also like writing about building web apps and working with web technology.
You can email us on email@example.com