Updating a collection
Updating the playlists table to insert the tags data.
Update the songs table to insert the tags data:
UPDATE songs SET tags = tags + {'2007'} WHERE id = 8a172618-b121-4136-bb10-f665cfc469eb; UPDATE songs SET tags = tags + {'covers'} WHERE id = 8a172618-b121-4136-bb10-f665cfc469eb; UPDATE songs SET tags = tags + {'1973'} WHERE id = a3e64f8f-bd44-4f28-b8d9-6938726e34d4; UPDATE songs SET tags = tags + {'blues'} WHERE id = a3e64f8f-bd44-4f28-b8d9-6938726e34d4; UPDATE songs SET tags = tags + {'rock'} WHERE id = 7db1a490-5878-11e2-bcfd-0800200c9a66;
A music reviews list and a schedule (map collection) of live appearances can be added to the table:
ALTER TABLE songs ADD reviews list<text>; ALTER TABLE songs ADD venue map<timestamp, text>;
Each element of a map, list, or map is internally stored as one Cassandra column. To update a set, use the UPDATE command and the addition (+) operator to add an element or the subtraction (-) operator to remove an element. For example, to update a set:
UPDATE songs SET tags = tags + {'rock'} WHERE id = 7db1a490-5878-11e2-bcfd-0800200c9a66;
To update a list, a similar syntax using square brackets instead of curly brackets is used.
UPDATE songs SET reviews = reviews + [ 'hot dance music' ] WHERE id = 7db1a490-5878-11e2-bcfd-0800200c9a66;
To update a map, use INSERT to specify the data in a map collection.
INSERT INTO songs (id, venue) VALUES (7db1a490-5878-11e2-bcfd-0800200c9a66, { '2013-9-22 12:01' : 'The Fillmore', '2013-10-1 18:00' : 'The Apple Barrel'});
Inserting data into the map replaces the entire map.