How to query a sub-element of the design document in CouchDB?

34 Views Asked by At

I have a couchdb database containing about 900 documents, with an average size of ~600KB. Each document is quite complex containing thousands of elements with 5-6 levels of depth. to speed up data search, I extracted some top-level information using a design document, where one of the entries look like this

{
    "id": "doc1",
    "key": "doc1",
    "value": {
        "name": "title",
        "length": 149085,
        "readme": "... ",
        "info": {
            "version": "1.0.0",
            "license": "CC0",
            "authors": [
                "...",
            ]
        }
    }
}

I would like to query the value.info.version field in the design document with a hope that this would be much faster than writing a _find command to do the ad-hoc search from the entire database. However, from reading the design document documentation, I wasn't able to find an API to retrieve subelement from the generated design document.

can this be done? or _find is the only way to do this?

1

There are 1 best solutions below

3
smathy On

The way to do this without resorting to a _find is to create a new view that emits whatever field you want to filter (search) by as they key. Then you can use startkey/endkey to filter out only those docs from the view.