Storing arrays in a document
Hi,
I'm relatively new to the NoSQL universe, and I'm looking for some guidance with the Memcached Java client and Couchbase.
Referring to Rags' presentation on Slideshare, if my model consists of Player, Plant and Player_Plant List, how do I go about storing the Player_Plant list in a distributed app scenario. If I have an in-memory Java object for Player1_Plant on one app server instance and I use client.set() to update the value, I could potentially be blindly overwritting changes done by another app instance. Do we use CAS operations to handle situations like these?
CASValue<Object> cas = client.gets("Player1_Plant");
CASResponse response = client.cas( "Player1_Plant" , cas.getCas(), mapper.writeValueAsString(player1_plantList));
...and then check the response?
And in what situations or use-cases are client.append() and client.prepend() used? Can they work with JSON?
Thanks.
Yes, CAS operations are the best way to ensure you have consistent updates to that document.
It is possible to use append/prepend, but that will not work with JSON documents because of the format. Some people use special characters, like "|" to delimit the field, rather than JSON and CAS.
With 2.0, you'll be able to do more with JSON documents, so that's generally recommended.