我们正在获取com.mongodb.MongoQueryException:
> Query failed with error code 13 while connecting to MongDB trhough
> spring-data.
MongoDB version 3.xSpring 4.1.6、mongo-java-driver - 3.0.2、spring-data-commons - 1.10.0.RELEASE、spring-data-mongodb - 1.7.0.RELEASE
无法对集合运行查找查询。
我可以使用相同的凭据在GUI上查看集合。
任何帮助都将不胜感激。
下面是完整的例外:
> org.springframework.data.mongodb.UncategorizedMongoDbException: Query
> failed with error code 13 and error message 'not authorized for query
> on <db.table>' on server xxx; nested exception is
> com.mongodb.MongoQueryException: Query failed with error code 13 and
> error message 'not authorized for query on db.table on server xxx
> at org.springframework.data.mongodb.core.MongoExceptionTranslator.translateExceptionIfPossible(MongoExceptionTranslator.java:96)
> at org.springframework.data.mongodb.core.MongoTemplate.potentiallyConvertRuntimeException(MongoTemplate.java:2002)
> at org.springframework.data.mongodb.core.MongoTemplate.executeFindMultiInternal(MongoTemplate.java:1885)发布于 2015-08-19 01:27:13
查看mongo XSD的2.6和3.0版本的java驱动程序,它们是不同的-似乎你仍然使用旧的方式进行身份验证。
<mongo:db-factory dbname="${mongo.database}" username="${mongo.user}"
password="${mongo.pwd}" mongo-ref="mongo"/>这只适用于2.6版本的java驱动程序,而不适用于3.0版本的java驱动程序。
将此mongo-client-option与凭据属性一起使用。
<mongo:mongo-client replica-set="${mongo.replica-set}" credentials="you need to put here user/password with specific DB">用于身份验证的username:password@database条目的逗号分隔列表。附加? uri.authMechanism允许指定身份验证质询机制。如果您尝试传递的凭据本身包含逗号,请用单引号将其引起来:'…'。
https://stackoverflow.com/questions/30634987
复制相似问题