Realm is an easy-to-use, offline-first database that lets mobile developers build better apps, faster.

Since our acquisition by MongoDB in May, we’ve continued investing in building an updated version of our mobile database – Realm Database 6.0.

We’re thrilled to announce that it’s now in beta, meaning we’ve hit a major milestone on our MongoDB Realm Roadmap. Realm Database 6.0 is now included in the Realm Java 7.0, Cocoa 6.0, and JS/RN 4.0 SDKs and will follow later in .NET/Xamarin 5.0.

A New Architecture

This effort lays a new foundation that further increases the stability of the Realm Database and allows us to quickly release new features in the future.

We’ve also increased performance with further optimizations still to come. We’re most excited that:

The new architecture makes it faster to look up objects based on a primary key

iOS benchmarks show faster insertions, twice as fast sorting, and ten times faster deletions

Code simplifications yielded a ten percent reduction in total lines of code and a smaller library

Realm files are now much smaller when storing big blobs or large transactions.

Frozen Objects

With this release, we’re also thrilled to announce that Realm now supports Frozen Objects, making it easier to use Realm with reactive frameworks.

Since our initial release of the Realm database, our concept of live, thread-confined objects has been key to reducing the code that mobile developers need to write. Objects are the data, so when the local database is updated for a particular thread, all objects are automatically updated too. This design ensures you have a consistent view of your data and makes it extremely easy to hook the local database up to the UI. But it historically came at a cost for developers using reactive frameworks.

Now, Frozen Objects allow you to work with immutable data without needing to extract it from the database. Instead, Frozen Objects act like immutable objects, meaning they won’t change. They allow you to freeze elements of your data and hand it over to other threads and operations, without throwing an exception - so it’s simple to use Realm when working with platforms like RxJava.

Using Frozen Objects

Freeze any ‘Realm’, ‘RealmList’, or ‘RealmObject’ and it will not be possible to modify them in any way. These Frozen Objects have none of the threading restrictions that live objects have, meaning they can be read and queried across all threads.

As an example, consider what it would look like if you were listening to changes on a live Realm using Kotlin, and then wanted to freeze query results before sending them on for further processing:

val realm : Realm = Realm . getDefaultInstance (); val results : RealmResults < Person > = realm . where < Person >(). beginsWith ( "name" , "Jane" ). findAllAsync () results . addChangeListener { liveResults -> val frozenResults : RealmResults < Person > = liveResults . freeze () val t = Thread ( Runnable { assertTrue ( frozenResults . isFrozen ()) // It is now possible to read objects on another thread val person : Person = frozenResults . first () person . name }) t . start () t . join () }

Since RxJava needs immutable objects, we also updated our RxJava support so all Realm Observable s and Flowable s now emit frozen objects by default. This means that it should be possible to use all operators available in RxJava without either using Realm.copyFromRealm() or running into an IllegalStateException :

val realm = Realm . getDefaultInstance () val stream : Disposable = realm . where < Person >(). beginsWith ( "name" , "Jane" ). findAllAsync (). asFlowable () . flatMap { frozenPersons -> Flowable . fromIterable ( frozenPersons ) . filter { person -> person . age > 18 } . map { person -> PersonViewModel ( person . name , person . age ) } . toList () . toFlowable () } . subscribeOn ( Schedulers . computation ()) . observeOn ( AndroidSchedulers . mainThread ) . subscribe { updateUI ( it ) } }

Frozen Objects are already available in the Realm Java SDKs, and will be available in the SDKs for other platforms soon. The APIs are still in beta, so if you have feedback please post it in Github and the Realm team will check it out!

A Strong Foundation for the Future

With the Realm Database 6.0 now in Beta and our first major feature released with Frozen Objects, we’re now focused on hitting the next milestones on our roadmap as we bring MongoDB Realm to public beta.

Want to learn more? Review the documentation.

Ready to get started? Download the database.

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.