风故故,也依依

Stand still in the wind.

导航

MongoDB学习——安全登录

/**
* Java + MongoDB in Secure Mode
*
* @author <a href="mailto:gerald.chen@qq.com">Gerald Chen</a>
* @version $Id: AuthTest.java,v 1.1 2011/05/27 07:24:04 gerald.chen Exp $
*/

public class AuthTest {
 
/** 数据库连接IP */
public static final String DB_HOST ="192.168.35.101";
 
/** 数据库连接端口 */
public static final int DB_PORT =27017;
 
public static void main(String[] args) throws Exception, MongoException {
      Mongo mongo =new Mongo(DB_HOST, DB_PORT);
      DB db = mongo.getDB("test_db");
 
      boolean auth = db.authenticate("gerald", "123456".toCharArray());
      System.out.println(auth);
 
      DBCollection collection = db.getCollection("test_collection");
      System.out.println(collection.getFullName());
 
}
 
}

posted on 2011-05-27 15:42  jadmin  阅读(221)  评论(0)    收藏  举报