Can I insert partial data into a Couchbase document


When I was researching the issue I faced with with the Node 2.0 documentation. This guide says the following sentence at the Atomic Operation chapter.

This operation is performed without any consideration for data type, thus appending a JSON document to a JSON document will result in an invalid object (for instance: {}{}).

For this reason I think the Couchbase server stores documents like indexed-db. Several fields for meta data and another field for main JSON data. Is it true ?

     _id              |         meta1      |        main data 
   an_Id_3XYZ               rev_08DO01546           {  JSON }

I’ll make a decision regarding to store all user data (puschased product, billing information, messages etc.) into a document. For this reason I think my document size will be increased up to 10 mb in time. At the same time I cannot get and put the entire of document when a user use the application.

If I use that way, can I insert/update partial data (in fact working an embedded document) into a Couchbase document ?

I’ve wrote the below for the sake of example. Can I insert a new item or update a current item in the purchased array field ?

    _id: "1", 
    username: "cody", 
    address: { street: "A Street", postalCode: "34349", city: "A City", province: "A Province" },
    purchased: [{ _id: 1, title:"Lawn chair", 
                    content: "Green color", 
                        image: "../images/products/img1.jpg",
                        date: "2014-10-24T14:57:28.348Z" 
                { _id: 2, title:"Space Truck", 
                    content: "1365 PS with Turbo", 
                        image: "../images/products/img59.jpg",
                        date: "2014-10-24T14:57:28.348Z" 

No, you cannot. The wire protocol does not have such operation, if you are talking about saving network traffic.

There are four commands which can amend document incrementally: append, prepend, increment and decrement. All of them are making assumptions about the document, and none of them can handle JSON objects. But if your parser can parse JSON streams like this


you probably can write a transcoder which can merge those “diffs” to {"items":[1,2]} while getting the value from the database. But this approach will turn document into “binary large object” for the server, and it will be harder to use in views for example.


thank you for your explanation and advice

Have a nice day…

Hey @efkan,

Another option would be to store the purchase histories in separate documents, and simply reference them from the user object, this would reduce the amount of data to read and write, and hopefully reduce the chances that you cross the 10mb limit.

Cheers, Brett

Hi Brett,

Thank you for your advice.