Chinaunix首页 | 论坛 | 博客

分类: Java

2015-06-09 10:36:58

    最近遇到服务器迁移,增加了mongodb的权限认证,所以导致之前的程序不能正确的执行,特意查看了相应的api
1. java连接mongodb
    MongoClient mongoClient;
    MongoCredential credential = MongoCredential.createCredential("user", "database", password);
    mongoClient = new MongoClient(new ServerAddress(ip, port), Arrays.asList(credential));
2. python连接mongodb
   from pymongo import MongoClient
    
    client = MongoClient("ip",port)
    client.database.authenticate("user","password")
    db = client.database
    collection = db.collection
阅读(14008) | 评论(1) | 转发(0) |
给主人留下些什么吧!~~

longly11082015-06-11 14:48:24

恩,不错啊

评论热议
请登录后评论。

登录 注册