I am implementing an android application that uses mongoDB database that is stored in mLab. The way i am connecting to the database is with code in my android application as follows:
private MongoCollection<Document> getCollectionn(String link, String coll){
//link is: mongodb://<user>:<password>@ds<port>.mlab.com:<port>/<db>
MongoClientURI uri = new MongoClientURI(link);
MongoClient client = new MongoClient(uri);
MongoDatabase db = client.getDatabase(uri.getDatabase());
return db.getCollection(coll);
}
I was wondering if this is the best way to connect with the database. I am reading that it has performance and security issues. Would it be better, for example, to connect with the database via a php file that is stored in a server and get the results from my queries from there and use them in my application. Is there some other way?
EDIT
From mongoLab documentation they are saying the following:
mLab databases can be accessed by applications in two ways.
The first method - the one we strongly recommend - is to connect using one of the available MongoDB drivers. You do not need to use our API if you use the driver. In fact, using a driver provides better performance, better security, and more functionality.
The second method, documented in this article, is to connect via mLab’s RESTful Data API. Use this method only if you cannot connect using a MongoDB driver.
Here is the documentation to their API.
So why would someone suggest to use the RESTful API while mongoLab strongly recommends the mongo java driver? Is it because its about Android?
Thanks!