'Insert multiple documents into couchdb

I'm fairly new to couchdb and am trying to insert some documents into it from a third party api.

I don't have complete control over the formatting from the source but I can get it very close to the format that _bulk_docs expects.

An example of data that can be sent is either:

[{"field1":"value1"},{"field2":"value2"}]

or

{"events":[{"field1":"value1"},{"field2":"value2"}]}

I would really like these to be separated and stored as two different documents. Bulk insert expects the key with the array to be named "docs" but I cannot change that.

Is there another way I can make this work?

I was trying to see if an update function is something that could work in this case but not sure if that gets triggered when the data comes in or if I can create multiple documents from one document using an update function.

Any help is much appreciated.

Thanks, Karan



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source