Update array field of a document

I am getting the document to be updated like this. Idea is to add one more dictionary/map element to the array. The document looks like this:

{id:'id', cycles: [{"id":1, "name":"cycle 1"}] }

now i want to add cycle 2 to the cycles array but got stuck here:

Document doc = database.getDocument(docId);

// get the field to be updated, which is an array.
Array ar = doc.getArray(“cycles”); // getting the data here well.
MutableDocument mutableDocument = document.toMutable();
//what comes here please?
database.save(mutableDocument);

You’ve done things in the wrong order here. Make the document mutable first, and then call getArray. A mutable document has a mutable array, a regular document does not.