2015-04-27 74 views
2

在副本集蒙戈殼牌,use products;db.auth('worker'.'a*******6');是好的,但在彈簧數據mongondb,我遇到了以下問題:CannotGetMongoDbConnectionException:無法驗證數據庫

Exception in thread "main" org.springframework.data.mongodb.CannotGetMongoDbConnectionException: Failed to authenticate to database [products], username = [worker], password = [a*******6] 
    at org.springframework.data.mongodb.core.ReflectiveDbInvoker.authenticate(ReflectiveDbInvoker.java:83) 
    at org.springframework.data.mongodb.core.MongoDbUtils.doGetDB(MongoDbUtils.java:127) 
    at org.springframework.data.mongodb.core.MongoDbUtils.getDB(MongoDbUtils.java:94) 
    at org.springframework.data.mongodb.core.SimpleMongoDbFactory.getDb(SimpleMongoDbFactory.java:197) 
    at org.springframework.data.mongodb.core.SimpleMongoDbFactory.getDb(SimpleMongoDbFactory.java:185) 
    at org.springframework.data.mongodb.core.MongoTemplate.getDb(MongoTemplate.java:1595) 
    at org.springframework.data.mongodb.core.MongoTemplate.execute(MongoTemplate.java:441) 
    at org.springframework.data.mongodb.core.MongoTemplate.doCreateCollection(MongoTemplate.java:1612) 
    at org.springframework.data.mongodb.core.MongoTemplate.createCollection(MongoTemplate.java:492) 
    at com.qixin.appmarket.service.test.TestMongodb.main(TestMongodb.java:24) 
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) 
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
    at java.lang.reflect.Method.invoke(Method.java:606) 
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120) 
+0

那麼,是什麼問題? –

+0

我有同樣的問題 – user1955934

回答

3

嘗試升級到spring-data-mongodb到最新版。我在使用版本1.7.2.RELEASE時遇到了驗證錯誤,但在更新至1.8.0.RELEASE後停止。

+0

更新springmongo版本幫助我 – Diyko

0

MongoDB,你可以使用:

use products 
db.createUser(
    { 
    user: "accountUser", 
    pwd: "password", 
    roles: [ "readWrite", "dbAdmin" ] 
    } 
)