MongoDB服务器应对身份进行验证才能为其提供服务,防止攻击者入侵。
MongoCredential credential = MongoCredential.createScramSha1Credential(username, databaseName, password);
List<MongoCredential> credentials = new ArrayList<MongoCredential>();
credentials.add(credential);
MongoClient mongoClient = new MongoClient(addrs,credentials);