Interested in speaking at MongoDB World 2022? Click here to become a speaker.
HomeLearnArticleRealm SDKs 10.0: Cascading Deletes, ObjectIds, Decimal128, and more

Realm SDKs 10.0: Cascading Deletes, ObjectIds, Decimal128, and more

Updated: Jan 11, 2022 |

Published: Oct 19, 2020

  • Realm
  • Mobile
  • Java
  • ...

By Ian Ward

Rate this article

The Realm SDK 10.0 is now Generally Available with new capabilities such as Cascading Deletes and new types like Decimal128.

#Release Highlights

We're happy to announce that as of this month, the new Realm Mobile Database 10.0 is now Generally Available for our Java/Kotlin, Swift/Obj-C, and JavaScript SDKs.

This is the culmination of all our hard work for the last year and lays a new foundation for Realm. With Realm 10.0, we've increased the stability of the database and improved performance. We've responded to the Realm Community's feedback and built key new features, like cascading deletes, to make it simpler to implement changes and maintain data integrity. We've also added new data types.

Realm .NET is now released as a feature-complete beta. And, we're promoting the Realm Web library to 1.0, replacing the MongoDB Stitch Browser SDK. Realm Studio is also getting released as 10.0 as a local Realm Database viewer for the 10.0 version of the SDKs.

With this release, the Realm SDKs also support all functionality unlocked by MongoDB Realm. You can call a serverless function from your mobile app, making it simple to build a feature like sending a notification via Twilio. Or, you could use triggers to call a Square API once an Order object has been synced to MongoDB Realm. Realm's Functions and Triggers speed up your development and reduce the code you need to write as well as having to stand up and maintain web servers to wait for these requests. And you now have full access to all of MongoDB Realm's built-in authentication providers, including the ability to call your own custom logic.

#Cascading Deletes

We're excited to announce that one of our most requested features - cascading deletes - is now available. Previous versions of Realm put the burden of cascading deletes on you as the developer. Now, we're glad to be reducing the complexity and amount of code you need to write.

If you're a Realm user, you know that object relationships are a key part of the Realm Database. Realm doesn't impose restrictions on how you can link your objects, no matter how complex relationships become. Realm allows one-to-one, one-to-many, many-to-many, and backlinks. Realm stores relationships by reference, so even when you end up with a complicated object graph, Realm delivers incredibly fast lookups by traversing pointers.

But historically, some use cases prevented us from delivering cascading deletes. For instance, you might have wanted to delete a Customer object but still keep a record of all of the Order objects they placed over the years. The Realm SDKs wouldn't know if a parent-child object relationship had strict ownership to safely allow for cascading deletes.

In this release, we've made cascading deletes possible by introducing a new type of object that we're calling Embedded Objects. With Embedded Objects, you can convey ownership to whichever object creates a link to the embedded object. Using embedded object references gives you the ability to delete all objects that are linked to the parent upon deletion.

Imagine you have a BusRoute object that has a list of BusStop embedded objects, and a BusDriver object who is assigned to the route. You want to delete BusRoute and automatically delete only the BusStop objects, without deleting the BusDriver object, because he still works for the company and can drive other routes. Here's what it looks like: When you delete the BusRoute, the Realm SDK will automatically delete all BusStops. For the BusDriver objects you don't want deleted, you use a regular object reference. Your BusDriver objects will not be automatically deleted and can drive other routes.

The Realm team is proud to say that we've heard you, and we hope that you give this feature a try to simplify your code and improve your development experience.

1// Define an object with one embedded object
3class Contact: Object {
4 @objc dynamic var _id = ObjectId.generate()
5 @objc dynamic var name = ""
7 // Embed a single object.
8 // Embedded object properties must be marked optional.
9 @objc dynamic var address: Address? = nil
11 override static func primaryKey() -> String? {
12 return "_id"
13 }
15 convenience init(name: String, address: Address) {
16 self.init()
17 = name
18 self.address = address
19 }
20 }
22// Define an embedded object
23class Address: EmbeddedObject {
24 @objc dynamic var street: String? = nil
25 @objc dynamic var city: String? = nil
26 @objc dynamic var country: String? = nil
27 @objc dynamic var postalCode: String? = nil
30let sanFranciscoContact = realm.objects(Contact.self)
31guard let sanFranciscoContact = realm.objects(Contact.self)
32 .filter(" = %@", "San Francisco")
33 .sorted(byKeyPath: "address.street")
34 .first,
35let sanFranciscoAddress = sanFranciscoContact.address else {
36 print("Could not find San Francisco Contact!")
37 return
40// prints City: San Francisco
41print("City: \( ?? "nil")")
43try! realm.write {
44 // Delete the instance from the realm.
45 realm.delete(sanFranciscoContact)
48// now the embedded Address will be invalid.
49// prints Is Invalidated: true
50print("Is invalidated: \(sanFranciscoAddress.isInvalidated)")

Want to try it out? Head over to our docs page for your respective SDK and take it for a spin!


ObjectIds are a new type introduced to the Realm SDKs, used to provide uniqueness between objects. Previously, you would need to create your own unique identifier, using a function you wrote or imported. You'd then cast it to a string or some other Realm primitive type. Now, ObjectIds save space by being smaller, making it easier to work with your data.

An ObjectId is a 12-byte hexadecimal value that follows this order:

  • A 4-byte timestamp value, representing the ObjectId's creation, measured in seconds since the Unix epoch
  • A 5-byte random value
  • A 3-byte incrementing counter, initialized to a random value

Because of the way ObjectIds are generated - with a timestamp value in the first 4 bytes - you can sort them by time using the ObjectId field. You no longer need to create another timestamp field for ordering. ObjectIDs are also smaller than the string representation of UUID. A UUID string column will take 36 bytes, whereas an ObjectId is only 12.

The Realm SDKs contain a built-in method to automatically generate an ObjectId.

1class Task: Object {
2 @objc dynamic var _id: ObjectId = ObjectId.generate()
3 @objc dynamic var _partition: ProjectId? = nil
4 @objc dynamic var name = ""
6override static func primaryKey() -> String? {
7 return "_id"
10convenience init(partition: String, name: String) {
11 self.init()
12 self._partition = partition
13 = name
14 }

Take a look at our documentation on Realm models by going here:


We're also introducing Decimal128 as a new type in the Realm SDKs. With Decimal128, you're able to store the exact value of a decimal type and avoid the potential for rounding errors in calculations.

In previous versions of Realm, you were limited to int64 and double, which only stored 64 bits of range. Decimal128 is a 16-byte decimal floating-point number format. It's intended for calculations on decimal numbers where high levels of precision are required, like financial (i.e. tax calculations, currency conversions) and scientific computations.

Decimal128 has over 128 bits of range and precision. It supports 34 decimal digits of significance and an exponent range of −6143 to +6144. It's become the industry standard, and we're excited to see how the community leverages this new type in your mathematical calculations. Let us know if it unlocks new use cases for you.

1class Task: Object {
2 @objc dynamic var _id: ObjectId = ObjectId.generate()
3 @objc dynamic var _partition: String = ""
4 @objc dynamic var name: String = ""
5 @objc dynamic var owner: String? = nil
6 @objc dynamic var myDecimal: Decimal128? = nil
7 override static func primaryKey() -> String? {
8 return "_id"

Take a look at our documentation on Realm models by going here -

#Open Sourcing Realm Sync

Since launching MongoDB Realm and Realm Sync in June, we've also made the decision to open source the code for Realm Sync.

Since Realm's founding, we've committed to open source principles in our work. As we continue to invest in building the Realm SDKs and MongoDB Realm, we want to remain transparent in how we're developing our products.

We want you to see the algorithm we're using for Realm Sync's automatic conflict resolution, built upon Operational Transformation. Know that any app you build with Realm now has the source algorithm available. We hope that you'll give us feedback and show us the projects you're building with it.

See the repo to check out the code

#About the New Versioning

You may have noticed that with this release, we've updated our versioning across all SDKs to Realm 10.0. Our hope is that by aligning all SDKs, we're making it easier to know how database versions align across languages. We can't promise that all versions will stay aligned in the future. But for now, we hope this helps you to notice major changes and avoid accidental upgrades.

#Looking Ahead

The Realm SDKs continue to evolve as a part of MongoDB, and we truly believe that this new functionality gives you the best experience yet when using Realm. Looking ahead, we're continuing to invest in providing a best-in-class solution and are working to to support new platforms and use cases.

Stay tuned by following @realm on Twitter.

Want to Ask a Question? Visit our Forums

Want to make a feature request? Visit our Feedback Portal

Want to be notified of upcoming Realm events such as our iOS Hackathon in November 2020? Visit our Global Community Page

Running into issues? Visit our Github to file an Issue.

Safe Harbor

The development, release, and timing of any features or functionality described for our products remains at our sole discretion. This information is merely intended to outline our general product direction and it should not be relied on in making a purchasing decision nor is this a commitment, promise or legal obligation to deliver any material, code, or functionality.

Rate this article
MongoDB logo
© 2021 MongoDB, Inc.


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