BLOGAnnounced at MongoDB.local NYC 2024: A recap of all announcements and updates — Learn more >

Database for Mobile Apps

Learn about what databases for mobile apps are, what to consider and why Atlas Device SDK is a great solution.
Deploy a Sample App
View documentation
Overview

Just like any other platform—such as web, desktop, or even Internet of Things (IoT)—mobile apps often require the storage of data. This data is usually stored in a database of some kind. In this article, we’re going to learn about the different types of databases for your application, why they’re important, and some of the options in terms of database products.

What are databases for mobile apps?

A database is a way to persist data for an application. A mobile database is a database specifically intended for persisting data in mobile applications, often on the device itself as local storage. This use of local storage is to allow the app to continue to work even when the device is offline or used as a cache for loading data in the event of slow network connectivity.

This often manifests as a file on the device which holds the data in the correct format for whatever database type is being used. However, as we will see later on, there are different types of mobile application databases, and how the information is stored will change depending on what type of database is being used.

The need to store data doesn’t change between application types, though. The application might want to store user preferences, profile information, cached data for faster loading times, or any number of different pieces of data. Why this data is stored doesn’t change between applications. Instead, the things to consider when choosing a database will be different for mobile apps. We will look further into this later in the article.

For specific advice for each platform, we have articles covering mobile databases for Android and mobile databases for iOS.

Different types of mobile app databases and storage solutions

Even within the mobile databases sphere, there are many different types of database and data storage solutions to consider.

Database Types

Relational database - Data is stored in tables using primary and foreign keys to form relationships between tables. The most common mobile relational database is SQLite.


Key-value database - This stores information by using keys as identifiers with an associated value. It’s often used to store small bits of information. Common examples in mobile databases would be UserDefaults in the iOS SDK, and SharedPreferences from Android.


Object-oriented database - This is a database that can work with complex data objects as used in object-oriented programming languages, such as Swift or Kotlin. It can execute fast queries with complex data. Code is often simpler as well due to similarities in structure between the database and object in code. Atlas Device SDKs provide an object-oriented database.

As well as the type of database itself, there are also different types of database storage.

Storage Types

Cloud storage - Cloud database storage is where the database is hosted and accessed within the cloud. Many of the above-mentioned database types have solutions that allow for the database to be hosted in the cloud. One example of a cloud database solution is MongoDB Atlas, a developer data platform that offers a database that can synchronize with Atlas Device SDKs on-device database, for sharing data across platforms and application types, amongst other great product features.


Local storage - This is where the database itself is stored locally to the device which hosts the application accessing the database. In the case of a mobile database, this would be stored on the phone.


Server storage - Although a cloud storage solution uses a server under the hood. Some may prefer to self-host a database on a server they own and manage—for example, for security reasons. This still requires internet access for the application.


Cloud/local storage - This hybrid approach used by products such as Atlas Device SDK in tandem with Device Sync, an Atlas App Service, allows for the best of both worlds. Data is available both on the device and in a cloud-hosted database, using sync to take care of keeping the data consistent between both.

How to select the correct database for mobile apps

Selecting the correct kind of database to use for your mobile application comes down to more than just how it’s stored. There are a few things to consider before deciding on the correct database for your requirements:

What sort of data will you be storing?

  • Different types of databases will suit different structures of data. Will the data itself be structured or unstructured? Will it be large files such as images, videos, or something else?

How often will the data be accessed?

  • If the data isn’t being accessed that often because, for example, the app won’t be accessed multiple times per day, then cloud hosting the data is an option. This is because as long as the device being used has access to the internet, it can access the cloud database.

  • If the data will be accessed frequently, a database that is stored locally might be a better option, as it means the data is available whenever it’s needed without the worry of slow or unavailable internet.

Where will users likely access the application?

  • If the application is intended for users who might have no access to reliable internet, such as engineers underground, a solution that stores the data locally is the best option.

  • If the hosting device for the application is going to be on the move frequently, where network speeds and access are intermittent (such as on a train), a local solution might be best.

  • If the mobile app is likely to be used above ground in areas with good connectivity, then a solution that suits the kind of data you will be storing is the main consideration.

How will the data be accessed and used?

  • Will you be joining data together from multiple sources and require carrying out complex queries?

What language will the application be written in?

  • Languages such as Swift, Objective-C, Java, Kotlin, and C#, often used to write native or cross-platform applications, are object-oriented languages. This means that objects are created within the application to represent pieces of information. If there are complex object-object relationships, then an object-oriented type database, such as Atlas Device SDK, is the best fit for high performance.
Atlas Device SDK mobile database

Atlas Device SDKs provide a general purpose, object-oriented database, meaning that it’s a great solution for many applications and their data storage requirements. It’s also fast, reactive, and scalable, taking advantage of the benefits of a hybrid cloud architecture thanks to Device Sync and MongoDB Atlas.

Atlas Device SDKs providing an object-oriented database, means that you can store objects directly in the database. This makes it easy to read and flexible. It can adapt to the shape of the data as it evolves with your application, thanks to the flexible schema. But you can always define one later if you want to. Data that is accessed together should be stored together. So, rather than storing data across tables using keys to form relationships, and requiring complex joins, related data is kept together in one document, leading to higher performance and querying and write speeds.

It uses an object-oriented data model, thanks to its JSON-like structure, meaning no object relational mapper (ORM) or database access object (DAO) is required. This improves developer productivity and experience, leading to producing more code in less time. Device Sync also removes the need to write complex network connection handling code, reducing lines of code and time to market.

Atlas Device SDK can seamlessly integrate with MongoDB Atlas, allowing you to reuse an existing database, or share data across multiple devices and platforms, whether that is mobile apps, desktop, web, or even IoT. Plus, thanks to Atlas App Services, developers have access to extra functionality such as authentication, triggers, and functions. These products all work together to build a fully-fledged, complex application with ease.

Summary

When thinking about creating an application for mobile devices, data storage is an important consideration. In this article, you have learned more about the different types of mobile application databases and what to consider when choosing a database. Finally, you learned more about the object-oriented database provided by Atlas Device SDKs, which is general purpose and can be used for many scenarios.

FAQ

Which database is best for mobile apps?

Which database to use for mobile apps depends on the requirements. You want to consider things like the structure of the data, how often it will need to be accessed, whether internet connectivity matters, etc.

A general-purpose database like the one provided by the Atlas Device SDKs is a great option as it can handle many different use cases, with the advantage of being able to sync with MongoDB Atlas’ document data model. Plus, thanks to Atlas Device Sync, users benefit from a hybrid solution that offers local and cloud storage, allowing for cross-device and cross-platform access, and increased network tolerance.

Can I use MongoDB for mobile apps?
Yes, MongoDB offers a mobile database through the use of Atlas Device SDKs. This is an object-oriented database and mobile SDK. When paired with Atlas Device Sync, part of Atlas App Services, data can be synchronized automatically between Atlas cloud-hosted database and local datastores. It also allows for use of other App Services products such as authentication, triggers, and functions.
Which database is used for Android apps?
There are a few options when it comes to which database to use for Android apps. The most common is SQLite, part of the Android SDK. But Atlas Device SDKs provide a general-purpose, object-oriented database. This is a fantastic option that can handle many use cases and comes with many benefits, including an out-of-the-box managed online-offline sync when paired with Atlas Device Sync.
Which database is used for iOS apps?
Many database options are available when it comes to iOS apps. The most common is SQLite. The Apple SDK comes with Core Data, which is more of an object graph management framework than a database itself, so is often paired with SQLite. However, Atlas Device SDKs provide an alternative general-purpose, object-oriented database. This is a fantastic option that can handle many use cases and comes with many benefits, including an out-of-the-box managed online-offline sync when paired with Atlas Device Sync.

Resources

general_content_expertise

Who Uses Atlas Device SDK

general_features_list

What's new in Atlas Device SDK

realm_product_family

Getting started with Device Sync

Deploy Atlas Device SDK in minutes

Deploy an iOS, Android, or cross-platform “To Do” app with real-time sync in minutes.
Get Started Now
An illustration of a database and device syncing over clouds.