Docs Menu

Find Object by Primary Key - Kotlin SDK

To find an object with a specific primary key value, open a realm and query the primary key field for the desired primary key value using realm.query(). Specify the object type as a type parameter passed to query():

// Search equality on the primary key field name
val frogs: Frog? = realm.query<Frog>("_id == $0", PRIMARY_KEY_VALUE).first().find()

find() runs a synchronous query on the thread it is called from. As a result, avoid using find() on the UI thread or in logic that could delay the UI thread. Prefer asFlow() in time sensitive environments.

←  Read - Kotlin SDKFind Objects of a Type - Kotlin SDK →
Give Feedback
© 2022 MongoDB, Inc.


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