只想查看此处,是否有任何机构遇到此问题
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 DB。看来连接对象都返回了,集合对象也返回了,但是在执行行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 collcetion,我可以看到admin用户那里readonly为false。
度过美好的一天
答案 0 :(得分:1)
检查此行中使用的数据库名称
DB db = getDBConnection(this.dbname);
是在openshift中创建的应用程序的名称。
看起来OpenShift会在MongoDB中预先创建一个具有该名称的数据库,并且您有权使用它。 但您无权创建和使用新的。
您可以在openshift中安装rockmongo并查看已有的数据库。