couchdb icon indicating copy to clipboard operation
couchdb copied to clipboard

Support Json Arrays or custom keys for _bulk_docs

Open karanpreetsingh1990 opened this issue 2 years ago • 1 comments

Support Json Arrays or custom keys for _bulk_docs

Summary

The Bulk doc insert works well but only if the data is sent in a very specific format. The "docs" key needs to have the array that needs to be inserted. It would be great if we had a way to customize that a bit.

Desired Behaviour

POST /db/_bulk_docs?arrayKey=keyname

Accepts the data below and adds the multiple documents under instead of "docs"

{
    "<keyname>": [
        {
            "key1": "value1"
        },
        {
            "key2": "value2"
        }
    ]
}

Also, it would be great to have a way of also passing the array directly and indicate as such in the parameter

POST /db/_bulk_docs?arrayKey=null

Accepts the data below and adds the multiple documents present in the array.

[
        {
            "key1": "value1"
        },
        {
            "key2": "value2"
        }
]

Additional context

I'm trying to send data to couchdb from a 3rd party tool that has limited capabilities for customization. I know of a few more tools that can send data to webhooks for reporting/audit/alerting etc. and couchdb would be perfect way to ingest,store, query and report on this data.

karanpreetsingh1990 avatar Feb 25 '22 12:02 karanpreetsingh1990

Years and years ago I believe this was the _bulk_docs API. We added the object wrapper for a reason that I vaguely recall as security-related, but I don't recall all the details offhand.

kocolosk avatar Feb 25 '22 20:02 kocolosk

I think it would be hard to justify adding support for multiple _bulk-docs formats at this point since it's a fairly established API at this point. Adding modes would make the API description a bit too confusing.

nickva avatar Oct 24 '22 18:10 nickva