Document Size with N1QL query

#1

Is there any way to get the size of a document using a N1QL query. I have seen it done using a view here:

http://blog.couchbase.com/calculating-average-document-size-documents-stored-couchbase

#2

how about something like this - this would give you the encoded size for each doc.

select length(ENCODE_JSON(default)) from default;

By the way, you can find more about the JSON functions here in the docs: http://developer.couchbase.com/documentation/server/4.5/n1ql/n1ql-language-reference/jsonfun.html

#3

Yes @cihangirb. Also,

SELECT ENCODED_SIZE(default) FROM default;

#4

Thank you. Those suggestions worked well.

1 Like
#5

I unable to find out the Doc size , can some one please help with step by step with a bucket name travel

#6
SELECT META(t).id, length(ENCODE_JSON(t)) AS size
FROM  `travel-sample` AS t 
LIMIT 3;

  "results": [
    {
        "id": "airline_10",
        "size": 120
    },
    {
        "id": "airline_10123",
        "size": 118
    },
    {
        "id": "airline_10226",
        "size": 116
    }
    ]
#7

I think this one would be more efficient with the virtual xattrs @vsr1.

#8

yeah , you are correct