Update a Collection - Kotlin SDK
To update a collection of objects in a realm:
- Query a realm for a collection of objects with realm.query().
- Open a write transaction with realm.write() or realm.writeBlocking().
- Update elements of the set of RealmResults returned by the query.
val tadpoles: RealmQuery<Frog> = realm.query<Frog>("age > $0", 2) for (tadpole in tadpoles.find()) { realm.write { findLatest(tadpole)?.name = tadpole.name + " Jr." } }
Note
You can only update objects within a write transaction.