Question

I have a database in Couch db with documents like:

{"foo":["bar1":"baz","bar2":18,"bar3":23.2]}

Is there a way for me to do batch checking of each value before inserting new documents?

What I want to achieve is if in any document in the database the key value pair foo.bar1 = baz and foo.bar2=1 exists where baz is equal to the new value I want to insert, the batch function should not insert the new document.

More concretely, the foo.bar is a datetime and if that datetime exists and another value in the same document is of a given value, no update shall be executed.

I could solve this by doing single requests for insert by first doing a request for the values and then let the client decide. But that will be very time consuming with all the data sent back and forth between client and couch db. Also I prefer to rely on the integrity of a database when doing this kinds of checks. Or is that the sql way of solving the problem?

Was it helpful?

Solution

You need to use Bulk Document API. After you send a list of desired keys to _all_docs, you will get a response with statuses. Not found keys will have status 'error' (not found)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top