dqg95034 2016-03-17 13:36
浏览 211

MongoDB - Java | 使用MongoDB Java Driver连接到mongoLab

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!

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥30 这是哪个作者做的宝宝起名网站
    • ¥60 版本过低apk如何修改可以兼容新的安卓系统
    • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
    • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
    • ¥50 有数据,怎么用matlab求全要素生产率
    • ¥15 TI的insta-spin例程
    • ¥15 完成下列问题完成下列问题
    • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
    • ¥15 YoloV5 第三方库的版本对照问题
    • ¥15 请完成下列相关问题!