Docs Menu

Update a Collection - Kotlin SDK

To update a collection of objects in a realm:

  1. Query a realm for a collection of objects with realm.query().
  2. Open a write transaction with realm.write() or realm.writeBlocking().
  3. 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.

←  Upsert an Object - Kotlin SDKDelete - Kotlin SDK →
Give Feedback
© 2022 MongoDB, Inc.

About

  • Careers
  • Investor Relations
  • Legal Notices
  • Privacy Notices
  • Security Information
  • Trust Center
© 2022 MongoDB, Inc.