gpt4 book ai didi

mongodb - com.mongodb.MongoException : not authorized for insert on myworld. 用户

转载 作者:可可西里 更新时间:2023-11-01 10:43:04 25 4
gpt4 key购买 nike

只是想在这里检查一下,有没有人遇到过这个问题

Caused by: com.mongodb.MongoException: not authorized for insert on myworld.Users
at com.mongodb.CommandResult.getException(CommandResult.java:100) [mongo-java-driver-2.10.1.jar:]
at com.mongodb.CommandResult.throwOnError(CommandResult.java:134) [mongo-java-driver-2.10.1.jar:]
at com.mongodb.DBTCPConnector._checkWriteError(DBTCPConnector.java:142) [mongo-java-driver-2.10.1.jar:]
at com.mongodb.DBTCPConnector.say(DBTCPConnector.java:183) [mongo-java-driver-2.10.1.jar:]
at com.mongodb.DBTCPConnector.say(DBTCPConnector.java:155) [mongo-java-driver-2.10.1.jar:]
at com.mongodb.DBApiLayer$MyCollection.insert(DBApiLayer.java:270) [mongo-java-driver-2.10.1.jar:]
at com.mongodb.DBApiLayer$MyCollection.insert(DBApiLayer.java:226) [mongo-java-driver-2.10.1.jar:]
at com.mongodb.DBCollection.insert(DBCollection.java:75) [mongo-java-driver-2.10.1.jar:]
at com.mongodb.DBCollection.insert(DBCollection.java:59) [mongo-java-driver-2.10.1.jar:]
at com.mongodb.DBCollection.insert(DBCollection.java:104) [mongo-java-driver-2.10.1.jar:]
at com.sandeep.myworld.dao.base.MongoAdapter.insertUser(MongoAdapter.java:46) [classes:]
at com.sandeep.myworld.dao.impl.UserServiceDaoImpl.importUser(UserServiceDaoImpl.java:19) [classes:]
at com.sandeep.myworld.services.impl.UserService.importUser(UserService.java:29) [classes:]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [rt.jar:1.7.0_79]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) [rt.jar:1.7.0_79]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) [rt.jar:1.7.0_79]
at java.lang.reflect.Method.invoke(Method.java:606) [rt.jar:1.7.0_79]
at org.jboss.ws.common.invocation.AbstractInvocationHandlerJSE.invoke(AbstractInvocationHandlerJSE.java:111)
at org.jboss.wsf.stack.cxf.JBossWSInvoker._invokeInternal(JBossWSInvoker.java:181)
... 31 more

我正在尝试从 Openshift 连接 mongo 数据库。好像返回了connection对象,collection对象也返回了,但是在执行table.insert这行,方法如下,异常就来了

        DB db = getDBConnection(this.dbname);
DBCollection table = db.getCollection(this.dbcollcetion.name());
BasicDBObject document = new BasicDBObject();
Field [] attributes = object.getClass().getDeclaredFields();
try {
for(Field field: attributes) {
field.setAccessible(true);
document.put(field.getName(), field.get(object));
}
} catch (IllegalArgumentException e) {
System.out.println("Exception in setting fields to mongo basicobject");
e.printStackTrace();
} catch (IllegalAccessException e) {
System.out.println("Exception in setting fields to mongo basicobject");
e.printStackTrace();
}

WriteResult write = table.insert(document);
return result;

非常感谢任何帮助,是否与 mongo db 中的访问有关,我已经检查了 system.users 集合,我可以看到那里的管理员用户只读为 false。

祝你今天愉快

最佳答案

检查此行中是否使用了数据库名称

DB db = getDBConnection(this.dbname);

是您在 openshift 中创建的应用程序的名称。

看起来 OpenShift 在 MongoDB 中预先创建了一个具有该名称的数据库,并且您有权使用它。但您无权创建和使用新的。

您可以在 openshift 中安装 rockmongo 并查看已经存在的数据库。

关于mongodb - com.mongodb.MongoException : not authorized for insert on myworld. 用户,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30720998/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com