An Android starter project for working with MongoDB Mobile & Stitch.
At MongoDB World 2018, Mongo announced the beta of MongoDB Mobile, which enables you to use Mongo on your Android and iOS devices. This starter app provides a way to get up and running quickly (with zero config), and then either customize it or steal the code for your own projects.
For a list of platforms supported by MongoDB Mobile, see the MongoDB Mobile docs.
-
Clone or download this repo.
-
Copy the MongoDB Mobile tarball from one of the following locations:
-
Extract the tarball, and then copy the contents of the /lib/ folder to /app/src/main/jniLibs/platform, where platform matches one of the 3 listed above. When finished, your directory structure should look similar to this:
MongoDbMobile_Starter |-> app |-> src |-> main |-> jniLibs |-> x86_64 (or arm64-v8a or armeabi-v7a) |-> cmake |-> pkgconfig |-> libaccumulator.so |-> etc.
-
Open the project in Android Studio.
-
Compile and run the project. The name of the database and collection have been pre-entered for you. Click
Get Remote Data
to fetch the data from Atlas. Ifsync data locally
is checked, the data will be copied to the MongoDB Mobile database, too. -
The app will switch to the Remote tab and display the JSON data that was returned. If you chose to sync the data, you can swipe or select the local tab to see the local data.
This app is configured to use a test account with some simple data. When you are ready to customize the app and use your own data, follow these steps:
-
Change the following values:
a. In
res/values/strings.xml
, replace starterappdata-tqlwq with your Stitch App Id. Don't have a Stitch app yet? Cool -- It's free and easy to get started!b. Depending on the authentication provider(s) you want to use, change the appropriate values in
strings.xml
. For example, this app defaults to using an API Key. If you also want to use API Key auth, in your Stitch app, generate a new API KEY, and then replace the value in theuserApiKey
field.c. If you haven't done so, add data to your Atlas instance and create the Stitch rules to access that data. See https://docs.mongodb.com/stitch/procedures/integrate-mongo/ for more information.
d. In
MainActivity.java
, on or near line 34, be sure to call the correct Auth method for your app if you are not using API Key Auth.e. In the
config_screen.xml
, remove or replace the text values for the database and collection EditText elements, but keep the hints. -
Compile and run the project.
MongoDB Mobile also works on iOS! See https://docs.mongodb.com/stitch/mongodb/mobile/mobile-overview/ to get started.
https://docs.mongodb.com/stitch/mongodb/mobile/build-mobile/