com.mongodb.MongoQueryException: Query failed with error code 13
2016-12-21 16:27
1746 查看
今天在用spring-data-mongo 配置mongodb的时候碰到个bug——com.mongodb.MongoQueryException: Query failed with error code 13。这个bug是说我鉴权没有通过,但我通过shell去访问是好的。
配置用的是spring官方的文档的配置:
这里要说一下mongodb3.0以后鉴权的方式就改变了,所以之前安装mongodb可视化工具的时候也碰到鉴权不通过的问题,也是因为mongodb版本问题。所以通过以上这段xml配置鉴权的方式只能在mongodb3.0版本以前,3.0版本以后要用下面的配置。
参考:http://stackoverflow.com/questions/30634987/com-mongodb-mongoqueryexception-query-failed-with-error-code-13
配置用的是spring官方的文档的配置:
<context:property-placeholder location="classpath:/com/myapp/mongodb/config/mongo.properties"/> <mongo:mongo host="${mongo.host}" port="${mongo.port}"> <mongo:options connections-per-host="${mongo.connectionsPerHost}" threads-allowed-to-block-for-connection-multiplier="${mongo.threadsAllowedToBlockForConnectionMultiplier}" connect-timeout="${mongo.connectTimeout}" max-wait-time="${mongo.maxWaitTime}" auto-connect-retry="${mongo.autoConnectRetry}" socket-keep-alive="${mongo.socketKeepAlive}" socket-timeout="${mongo.socketTimeout}" slave-ok="${mongo.slaveOk}" write-number="1" write-timeout="0" write-fsync="true"/> </mongo:mongo> <mongo:db-factory dbname="database" mongo-ref="mongo"/> <bean id="anotherMongoTemplate" class="org.springframework.data.mongodb.core.MongoTemplate"> <constructor-arg name="mongoDbFactory" ref="mongoDbFactory"/> </bean>
这里要说一下mongodb3.0以后鉴权的方式就改变了,所以之前安装mongodb可视化工具的时候也碰到鉴权不通过的问题,也是因为mongodb版本问题。所以通过以上这段xml配置鉴权的方式只能在mongodb3.0版本以前,3.0版本以后要用下面的配置。
<context:property-placeholder location="classpath:mongo.properties" file-encoding="UTF-8"/> <mongo:mongo-client id="mongo-client" host="${mongo.host}" port="${mongo.port}" credentials="${mongo.username}:${mongo.password}@${mongo.database}"> <mongo:client-options write-concern="1"/> </mongo:mongo-client> <mongo:db-factory id="mongoDbFactory" dbname="${mongo.database}" mongo-ref="mongo-client" /> <bean id="mongoTemplate" class="org.springframework.data.mongodb.core.MongoTemplate"> <constructor-arg name="mongoDbFactory" ref="mongoDbFactory"/> </bean>
参考:http://stackoverflow.com/questions/30634987/com-mongodb-mongoqueryexception-query-failed-with-error-code-13
相关文章推荐
- mongodb 报错:Query failed with error code 13 and error message 'not authorized for query on ..."
- Error - RtlWerpReportException failed with status code :-1073741823. Will try to launch the process
- 有关Error - RtlWerpReportException failed with status code :-1073741823.的解决方法
- Query failed with error code 96 and error message 'Executor error during find command: OperationFail
- com.mongodb.MongoException: Runner error: Overflow sort stage buffered data 错误分析
- Qt 跨线程初始化变量,程序奔溃(Error - RtlWerpReportException failed with status code :-1073741823.)
- Error:(63, 13) Failed to resolve: com.tencent.mm.opensdk:wechat-sdk-android-with-mta:+
- Qt error ------ 出现Error - RtlWerpReportException failed with status code :-1073741823. Will try to launch the process directly
- MondoDB Query failed with error code 2 and error message 'Projection cannot have a mix of inclusion
- The compiler failed with error code 128的问题
- Error creating bean with name 'userService': Injection of resource methods failed; nested exception is org.springframework.beans
- ognl.MethodFailedException:Error setting express'XXXXX' with value '[Ljava.lang.String的愿因
- COM class factory for component with CLSID {00024500-0000-0000-C000-000000000046} failed due to the following error: 80070005.
- 异常:Retrieving the COM class factory for component with CLSID {00024500-0000-0000-C000-000000000046} failed due to the following error: 80070005 拒绝访问
- Uncaught exception com_exception with message Failed to create COM object
- error HLP: Help compilation failed with code 1
- office2010 x64 Retrieving the COM class factory for component with CLSID {000209FF-0000-0000-C000-000000000046} failed due to the following error: 800
- 解决error: linker command failed with exit code 1类似的错误
- OCIEnvNlsCreate failed with return code -1 but error message text was not available.
- Retrieving the COM class factory for component with CLSID {00024500-0000-0000-C000-000000000046} failed due to the following error: 80070005.