Document Size with N1QL query

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

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: Couchbase SDKs

Yes @cihangirb. Also,

SELECT ENCODED_SIZE(default) FROM default;

1 Like

Thank you. Those suggestions worked well.

1 Like

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

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
    }
    ]
1 Like

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

yeah , you are correct