Reputation: 8076
Is it possible to store an array
var a=[
{"id":"1", "value":null},
{"id":"2", "value":null},
{"id":"3", "value":null},
{"id":"4", "value":null},
{"id":"5", "value":null}
];
in a couchbase membase with a document id
if sure, is there a way to get one element, such as
{"id":"2", "value":null}
and add/remove one element,such as
{"id":"6", "value":null}
?
your comment welcome
Upvotes: 2
Views: 302
Reputation: 1195
As alternative instead of using JSON, a binary format could be used instead. Which will allow the use of the append operation. In this case for a delete you could append with the id prefixed with a minus sign.
For example the data could look like this:
id:"1",value:"null"
id:"2",value:"null"
-id:"1"
At some point you will have to grab the whole document and "clean" it up to stop it growing unbounded. If a delete operation is the unlikely case then it might be worth grabbing the whole document and deleting the id instead of appending with the minus.
Befits
Costs
The befits only outweigh the costs when working on very large objects.
Upvotes: 0
Reputation: 485
Is it possible to store an array
Yes, you just need to serialize it
and add/remove one element
No, you will need to request all document by id, deserialize it's to array, remove element, serialize array and update document.
Upvotes: 1