Navigation

Set up a MongoDB Mobile Project

Deprecation

MongoDB has deprecated MongoDB Mobile. We are focusing our efforts on Realm, the most popular database for mobile devices.

Stay up to date and see what we have planned.

Overview

Before you begin coding an Android or iOS app that uses MongoDB Mobile, there are a few short steps required to set up your project. The following sections discuss the prerequisites, and then show you how to prepare your project.

Check Your Environment

To build a Stitch app that uses MongoDB Mobile, you need:

  • Android Studio or another IDE. The steps below have been tested with the latest version of Android Studio.
  • Support for API Level 21 or higher.

We also recommend the following device capabilities:

  • An ARM32, ARM64, or x86_64 device that is running an armeabi-v7a, arm64-v8a, or x86_64 image of Android 5.0 (Lollipop) or later.

Supported Device Architectures

MongoDB Mobile does not support x86 devices. By default, Android Studio selects an x86 image for AVD deployments, so if you are deploying your Android app to an AVD, be sure to select an x86_64 image for the AVD. Otherwise, you will see an error message similar to the following:

com.mongodb.embedded.client.MongoClientEmbeddedException: Failed to load the mongodb library: ‘mongo_embedded_capi’. Native library (com/sun/jna/android-x86/libjnidispatch.so) not found in resource path (.)

To build a Stitch app that uses MongoDB Mobile, you need to have Xcode and cocoapods installed. If you do not have cocoapods installed, you can install it from a terminal window with the following commands:

$ sudo gem install cocoapods

Once these prerequisites are met, you are ready to start building your mobile app.

Procedure

To set up a new project that will use MongoDB Mobile, follow these steps:

  1. Open a project in Android Studio, or create a new project. Be sure to set the minimum API level for the project to 21 or higher.

  2. Add the following dependencies to the Module-level Build.gradle file:

    implementation 'org.mongodb:stitch-android-sdk:4.1.0'
    
  3. In the android section of the same Module-level Build.gradle file, add the following compileOptions section:

    compileOptions {
       sourceCompatibility = JavaVersion.VERSION_1_8
       targetCompatibility = JavaVersion.VERSION_1_8
    }
    
  4. Sync the application to incorporate these changes.

  1. Create new project in Xcode, or open an existing project. Set the Language to Swift.

  2. In a terminal window, navigate to the project directory created by Xcode, and run the following command to automatically generate a Podfile:

    $ pod init
    
  3. In Xcode, add the necessary the necessary pods to the Podfile:

    pod 'StitchSDK', '~> 5.0.0'
    pod 'StitchLocalMongoDBService', '~> 5.0.0'
    
  4. In the terminal window, run the following commands:

    $ pod repo update
    $ pod install
    

    The pod install command creates a new XCode .xcworkspace file for your project that includes the dependencies listed in the Podfile.

  5. Quit XCode, and then re-open the project using the newly-created .xcworkspace file.

You can now use the Stitch SDKs to sync data between the local database and Atlas, or work with just the local database (MongoDB Mobile).