> On 02 Oct 2016, at 14:29, Filippo Fadda <[email protected]>
> wrote:
>
> Well, that's not what I meant. What I want is a query parameter to get only
> the specified document’s fields on a simple GET /{db}/{docid}. CouchDB should
> parse the JSON and returns only the required fields, because in a real
> scenario there are times you don’t need the entire document, but just some
> fields. Lazy Loading is a well known pattern and it’s really effective.
Re-post from my original email ;)
## Sub-Document Operations
Currently a doc update needs the whole doc body sent to the server. There are
some obvious performance improvements possible. For the longest time, I wanted
to see if we can model sub-document operations via JSON Pointers[2]. These
would roughly allow pointing to a JSON value via a URL.
For example in this doc:
{
"_id": "123abc",
"_rev": "zyx987",
"contact": {
"name": "",
"address": {
"street": "Long Street",
"nr": 123
"zip": "12345"
}
}
An update to the zip code could look like this:
curl -X POST $SERVER/db/123abc/_jsonpointer/contact/address/zip?rev=zyx987 -d
'54321'
GET/DELETE accordingly. We could shortcut the `_jsonpointer` to just `_` if we
like the short magic.
JSONPointer can deal with nested objects and lists and works fairly well for
this type of stuff, and it is rather simple to implement (even I could do it:
https://github.com/janl/erl-jsonpointer/blob/master/src/jsonpointer.erl — This
idea is literally 5 years old, it looks like, no need to use my code if there
is anything better).
This is just a raw idea, and I’m happy to solve this any other way, if somebody
has a good approach.
[2] https://tools.ietf.org/html/rfc6901
Best
Jan
--
>> On 30 Sep 2016, at 20:23, Nick Vatamaniuc <[email protected]> wrote:
>>
>> Hi Filippo,
>>
>>> Lazy Loading
>>> ——————
>>> I don’t know if CouchDB 2.0 comes with such a feature, but I would like to
>>> have a mechanism to get just some document’s fields. Sometime I just need
>>> the title or whatever, but I have to get the entire document. I would like
>>> to request just a set of fields when I retrieve a document from the
>>> database.
>>
>> There is pr to do something like this with _change feeds and mango
>> selectors. It adds an additional fields parameters to return only some
>> fields from the doc. So if the doc is 10MB and you just want to return
>> 1 field:
>>
>> https://github.com/apache/couchdb-couch/pull/177
>>
>> Cheers,
>> -Nick
>
--
Professional Support for Apache CouchDB:
https://neighbourhood.ie/couchdb-support/