MongoDB服务器应对身份进行验证才能为其提供服务,防止攻击者入侵。

    1. MongoCredential credential = MongoCredential.createScramSha1Credential(username, databaseName, password);
    2. List<MongoCredential> credentials = new ArrayList<MongoCredential>();
    3. credentials.add(credential);
    4. MongoClient mongoClient = new MongoClient(addrs,credentials);