NoSQL Zone is brought to you in partnership with:

Mark is a graph advocate and field engineer for Neo Technology, the company behind the Neo4j graph database. As a field engineer, Mark helps customers embrace graph data and Neo4j building sophisticated solutions to challenging data problems. When he's not with customers Mark is a developer on Neo4j and writes his experiences of being a graphista on a popular blog at http://markhneedham.com/blog. He tweets at @markhneedham. Mark is a DZone MVB and is not an employee of DZone and has posted 492 posts at DZone. You can read more from them at their website. View Full User Profile

CouchDB: 'Badmatch' When Executing View

01.04.2013
| 1967 views |
  • submit to reddit

I’ve been playing around with CouchDB again in my annual attempt to capture the links appearing on my twitter stream and I managed to create the following error for myself:

$ curl http://127.0.0.1:5984/twitter_links/_design/cleanup/_view/find_broken_links
{"error":"badmatch","reason":"{\n   \"find_broken_links\": {\n       \"map\": \"function(doc) {   \nvar prefix = doc.actual_link.match(/.*/);      

It turns out this error is because I’ve managed to create new line characters in the view while editing it inside CouchDBX. D’oh!

A better way is to edit the view in a text editor and then send it to CouchDB using curl.

The proper way to update a view would be to add a ‘_rev’ property to the body of the JSON document but I find it annoying to go and edit the document so I’ve just been deleting and then recreating my views.

$ curl -X GET http://127.0.0.1:5984/twitter_links/_design/cleanup/
{"_id":"_design/cleanup","_rev":"1-8be14d29f183b61f1ade160badef3f75","views"...}
$ curl -X DELETE http://127.0.0.1:5984/twitter_links/_design/cleanup?rev=1-8be14d29f183b61f1ade160badef3f75
{"ok":true,"id":"_design/cleanup","rev":"2-9fa15c1fdbb7cbaa659d623bc897b9da"}
$ curl -X PUT http://127.0.0.1:5984/twitter_links/_design/cleanup -d @cleanup.json
{"ok":true,"id":"_design/cleanup","rev":"17-b0763381b79f3fda843f57a7dcc842e1"}

I guess there’s probably a library somewhere which would encapsulate all that for me but I’m just hacking around at the moment.

It’s interesting to to see how you interact differently with a document database compared to what you’d do with a relational one with respect to optimistic concurrency.

Published at DZone with permission of Mark Needham, author and DZone MVB. (source)

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)