I am going to revive this topic and say that the MongoDB Java driver is currently compatible with Android. Some novice developers may have trouble getting their applications to use the MongoDB java library, so Iβll just outline what you need to do (although this may all be outdated by the time you read this).
Browse to the build.gradle file of your application. Add this "compile" entry under your dependencies (you may have to replace the version):
dependencies { ... implementation 'org.mongodb:mongo-java-driver:3.0.3' }
As you can see, the driver version for this post is 3.0.3. You can find the current version by searching for βmongo-java-driverβ or any other related term at http://search.maven.org .
If you connect to an external database, of course, you need to add the INTERNET permission to your manifest. Connecting to one is pretty simple. Here is an example. Replace 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 do all this in the AsyncTask class.
Following the Java tutorials at https://www.mongodb.org/ should be relatively simple from now on.
Astral1990 Sep 12 '15 at 18:27 2015-09-12 18:27
source share