couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Zachary Zolton <zachary.zol...@gmail.com>
Subject Re: Get Document Size
Date Fri, 04 Dec 2009 16:08:25 GMT
This seems to work for attachments:

function(doc) {
  if (doc['_attachments']) {
    var attachementSize = 0;
    for each (var stub in doc['_attachments']) {
      attachementSize += stub.length;
    }
    emit(null, attachementSize);
  }
}


On Fri, Dec 4, 2009 at 9:46 AM, Sebastian Cohnen
<sebastiancohnen@googlemail.com> wrote:
> this still does not include the documents attachments...
>
> On 04.12.2009, at 16:33, Zachary Zolton wrote:
>
>> You mean something like this map function?
>>
>> function(doc) {
>>  function toJson() {
>>    // code...
>>  }
>>
>>  emit(doc.someAttr, length(toJson(doc)));
>> }
>>
>>
>> On Fri, Dec 4, 2009 at 3:46 AM, Andreas Pavlogiannis
>> <paulogiann.couchdb@gmail.com> wrote:
>>> That might work for a single document, but I  'd rather calculate the size
>>> inside a map function so that I can then use a reduce to sum up.
>>>
>>> 2009/12/4 Sebastian Cohnen <sebastiancohnen@googlemail.com>
>>>
>>>> what about doing a HEAD request and look for Content-Length?
>>>>
>>>> {~} I curl -I http://localhost:5984/test/DOCUMENT-ID
>>>> HTTP/1.1 <http://localhost:5984/test/DOCUMENT-ID%0AHTTP/1.1> 200 OK
>>>> Server: CouchDB/0.11.0b60a6b3e7-git (Erlang OTP/R13B)
>>>> Etag: "1-1a6c2a80b8615b2399ff5ba66d18534d"
>>>> Date: Fri, 04 Dec 2009 09:38:34 GMT
>>>> Content-Type: text/plain;charset=utf-8
>>>> Content-Length: 169
>>>> Cache-Control: must-revalidate
>>>>
>>>>
>>>> On 04.12.2009, at 10:17, Andreas Pavlogiannis wrote:
>>>>
>>>>> Hello,
>>>>>
>>>>> Is there a uniform way to obtain a document's size (attachments' size
>>>> included) ?
>>>>>
>>>>> Thanks, Andreas
>>>>
>>>>
>>>
>
>

Mime
View raw message