Does anyone know how does MondgoDB works on Android.
Does it work locally and you the data gets replicated later?
Does work only online with just a web backend?

- 16,800
- 14
- 110
- 131

- 1,833
- 6
- 20
- 25
-
1We've been looking for something similar and the closest thing we've found is http://www.couchbase.com/products-and-services/couchbase-mobile – Devraj Jul 31 '11 at 06:57
-
1Almost all the answers are dated, please look into this https://realm.io/docs/java/latest – humble_wolf Jul 02 '19 at 01:31
7 Answers
MongoDB has downloads for several operating systems. However, Android is not one of those systems.
People use MongoDB as a "web service" for storing data, but it does not have any features to support multi-master replication or your occasionally connected mobile scenario.
If you need these types of features, you'll want to check out CouchDB which specifically targets this scenario with Android Couchbase.
-
3This question was answered in Jul 2011. How does the state of things look now in Jun 2013 ? – Jakub Czaplicki Jun 05 '13 at 11:37
-
5The Downloads page for MongoDB still lists the same support. And frankly, MongoDB is really _not_ designed for devices like Android. The way it maps data into memory is not a really good idea for small devices with limited RAM. The Android Couchbase project seems to have been abandoned and replaced with a "Lite" version: https://github.com/couchbase/couchbase-lite-android – Gates VP Jun 06 '13 at 16:46
-
4Also checkout PouchDB. It is a couchdb implementation that uses the browser's db for storage. Works on Android: http://pouchdb.com/ – Mike McKay Jul 05 '13 at 15:26
-
4The mongo-java-driver will now work on Android to connect to a web server with MongoDB. – Anonsage Dec 07 '13 at 07:38
I'm going to revive this thread and say that MongoDB's Java driver IS currently compatible with Android. Some novice developers might have trouble getting their apps to use MongoDB's java library, so I'll just outline what you have to do (though all of this could be obsolete by the time you're reading this).
Go to your app build.gradle file. Add this "compile" entry under your dependencies (you will probably have to replace the version):
dependencies {
...
implementation 'org.mongodb:mongo-java-driver:3.0.3'
}
As you can see, the driver's version as of this post is 3.0.3. You can find the current version by searching "mongo-java-driver" or any related terms at http://search.maven.org.
If you're connecting to an external database, you will of course need to add the INTERNET permission to your manifest. Connecting to one is pretty simple. Here's an example. Replace the username, password, host domain, port, and database name:
MongoClientURI uri = new MongoClientURI( "mongodb://username:password@www.example.com:12345/db-name" );
MongoClient mongoClient = new MongoClient(uri);
MongoDatabase db = mongoClient.getDatabase(uri.getDatabase());
Since this is network related, you will need to run all of that in an AsyncTask class.
Following the java tutorials on https://www.mongodb.org/ should be relatively straightforward from here on out.

- 899
- 9
- 17

- 413
- 5
- 6
-
1This might repeat the scenario which happened when apache lib was used to do http communications where Android had more optimized versions. People faced problems when android depricated support to it. – Neji Sep 30 '16 at 07:58
-
1Connecting to mongodb directly from an android app has several drawbacks and should be avoided if possible. From the security perspective server location and credentials al available to anyone who can de-compile your application. From the operations perspective it becomes hard or impossible to manage de connection pools and various performance or scalability issues may arise. – cjungel Nov 18 '16 at 12:53
-
2Irony is that dear @Astral1990 you look novice here, you are talking about mongo client and here we are looking for a local mongodb object/document storage solution. – Ravinder Payal May 05 '18 at 14:24
-
Great new Android application
No Need to root your Phone and You Can Run your js File From anywere.
MongoDB (from humongous) is a free and open-source cross-platform document-oriented database program. Classified as a NoSQL database program, MongoDB uses JSON-like documents with schemas.
Usage:
1: install Dory mongoDB Server
2: run your Server
3: install Dory node.js
4: run this code in your js file:
Code:
var mongoose = require('mongoose');
mongoose.connect('mongodb://localhost/test', { useMongoClient: true });
mongoose.Promise = global.Promise;
var Cat = mongoose.model('Cat', { name: String });
var kitty = new Cat({ name: 'Zildjian' });
kitty.save(function (err) {
if (err) {
console.log(err);
} else {
console.log('meow');
}
});
Enjoy.

- 8,406
- 21
- 60
- 103
Unfortunately Mongo Java Driver 3.8.0 is not compatible with Android anymore: https://gitlab.com/mvysny/umn/issues/1 and they don't even claim Android support. Maybe following the unofficial fork or trying GnuSasl could help? mongodb 3.x driver Android compatibility

- 3,088
- 28
- 39
MongoDB is also available for android
The only problem is that it does not have well-structured documentation for android..
I recently managed to connect my android application to the remote database
here is a sample unit application https://github.com/i-sachinkumar/MongoDB-for-Android
Its readme file contains all the steps to be followed in the back-end as well as in the android studio

- 11
- 1
Reactivating this Topic again after 2 years.
I was looking for an android app exactly like MongoDB Compass, but couldn't find "exactly" like it. So deciding to make one (and open source it)
Based on links given in @Astral1990's answer, I found this.
Now for a gist:
Gradle file: (more info here)
implementation 'org.mongodb:mongodb-driver-sync:4.2.3'
For creating the client: (more info here)
MongoClient mongoClient = MongoClients.create("mongodb://user1:pwd1@host1/?authSource=db1");
Then other things:
// get db
MongoDatabase database = mongoClient.getDatabase("test");
// get collection in db
MongoCollection<Document> coll = database.getCollection("myTestCollection");
// list collections (permission has to be present)
for (String name : database.listCollectionNames()) {
System.out.println(name);
}

- 520
- 7
- 9
It isn't possible to install MongoDB in android devices because the MongoDB's latest releases doesn't support android device's CPU architecture.
But I read an article on codipher.com and i gave it a try and it finally worked, i was able to use MongoDB on my android phone.
Here is the link: https://codipher.com/install-mongodb-on-android/

- 241
- 2
- 12