MongoDB on Android
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?
Solution 1:
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.
Solution 2:
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:[email protected]: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.
Solution 3:
Dory mongoDB Server
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. 😉
Solution 4:
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