开发者

CouchDB Recursive throw-away Queries

Not exactly sure what to call this, but in SQL I often find myself doing something like this while developing:

DELETE FROM people WHERE name == "John"

This is often used when I've just imported a bunch of data with a batch importer, and want to clear out a few results but not then entire data set. How do I go about doing this in CouchDB? I can easily make a map function

function(doc) {
   if (doc.Name == "John") 
       emit(doc._id, null);
}

And then delete the returned _ids...but that would require me to write some sort of front-end app to take these _ids and perform the DELETEs. Sometimes my queries are much more complex, and would require a few queries, followed by a delete, followed by another query and an update.

What's the 开发者_JAVA技巧accepted method of doing this sort of map/delete and perhaps a map/update?


The accepted method is pretty much just as you describe. Query the view and then delete the returned IDs. This isn't as bad as it sounds though. A quick script in your choice of language with a CouchDB library and you are essentially just moving the logic of your SQL into a language with more power. Some might consider this benefit. YMMV

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜