- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
使用现有数据库的正确登录凭据在 Java 中测试 MongoDB 连接失败。显示 com.mongodb.CommandFailureException
。
这可能是不同版本的 MongoDB 之间的不匹配,因为我使用的是为版本 2.6 编写的代码,并使用版本 3 运行它。不同版本的 MongoDB 驱动程序之间出现这种情况的可能性较小,因为我使用的是测试代码的同一版本 (mongo-java-driver 2.12.4
)。
如何修复此错误并使其与一系列 MongoDB 版本兼容?
String dbName = "test_db";
String host = "localhost";
Integer port = 27017;
String username = "admin";
String password = "password";
static Logger log = Logger.getLogger(MongoTest.class.getName());
log.debug("DBNAME:"+dbName+"\nHOST:"+host+"\nPORT:"+port+"\nUSERNAME:"+username+"\nPASSWORD:"+password+"\n");
MongoCredential credential = MongoCredential.createMongoCRCredential(username, dbName, password.toCharArray());
List<MongoCredential> auths = new ArrayList<MongoCredential>();
auths.add(credential);
MongoClient mongo = new MongoClient(new ServerAddress(host, port), auths);
DB db = mongo.getDB(dbName);
log.debug("DB:"+db); // not null
DBCollection dbCollection = db.createCollection("__test__", new BasicDBObject()); // FAIL
mongo.log
:
2015-12-04T15:55:36.148+0100 I NETWORK [initandlisten] connection accepted from 127.0.0.1:7273 #79 (18 connections now open)
2015-12-04T15:55:36.242+0100 I NETWORK [initandlisten] connection accepted from 127.0.0.1:7274 #80 (19 connections now open)
2015-12-04T15:55:36.256+0100 I ACCESS [conn80] authenticate db: test_db { authenticate: 1, user: "admin", nonce: "xxx", key: "xxx" }
2015-12-04T15:55:36.258+0100 I ACCESS [conn80] Failed to authenticate admin@test_db with mechanism MONGODB-CR: AuthenticationFailed MONGODB-CR credentials missing in the user document
2015-12-04T15:55:36.265+0100 I NETWORK [conn80] end connection 127.0.0.1:7274 (18 connections now open)
2015-12-04T15:55:36.282+0100 I NETWORK [initandlisten] connection accepted from 127.0.0.1:7275 #81 (19 connections now open)
2015-12-04T15:55:36.301+0100 I NETWORK [conn79] end connection 127.0.0.1:7273 (18 connections now open)
2015-12-04T15:55:36.301+0100 I NETWORK [conn81] end connection 127.0.0.1:7275 (18 connections now open)
异常(exception):
com.mongodb.CommandFailureException: { "serverUsed" : "localhost:27017" , "ok" : 0.0 , "errmsg" : "auth failed" , "code" : 18}
at com.mongodb.CommandResult.getException(CommandResult.java:76)
at com.mongodb.CommandResult.throwOnError(CommandResult.java:131)
at com.mongodb.DBPort$NativeAuthenticator.authenticate(DBPort.java:652)
at com.mongodb.DBPort.authenticate(DBPort.java:364)
at com.mongodb.DBPort.checkAuth(DBPort.java:375)
at com.mongodb.DBTCPConnector.doOperation(DBTCPConnector.java:209)
at com.mongodb.DBCollectionImpl.sendWriteCommandMessage(DBCollectionImpl.java:477)
at com.mongodb.DBCollectionImpl.writeWithCommandProtocol(DBCollectionImpl.java:427)
at com.mongodb.DBCollectionImpl.insertWithCommandProtocol(DBCollectionImpl.java:387)
at com.mongodb.DBCollectionImpl.insert(DBCollectionImpl.java:186)
at com.mongodb.DBCollectionImpl.insert(DBCollectionImpl.java:165)
at com.mongodb.DBCollection.insert(DBCollection.java:93)
at com.mongodb.DBCollection.insert(DBCollection.java:78)
at com.mongodb.DBCollection.insert(DBCollection.java:120)
at com.scs.setup.webapp.util.Mongo.isConnectionValid(Mongo.java:39)
at com.scs.setup.webapp.controller.AjaxActionTest.isMongoConnectionValidDefault(AjaxActionTest.java:85)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
最佳答案
通过在 Mongo (3.0.7) CLI 中正确添加用户解决了该问题,我尝试在 admin
数据库上运行它,而它应该在 test_db
数据库上运行:
mongo --authenticationDatabase db_name -u username -p password
(Connected to Mongo CLI client...)
> use test-db;
> db.createUser(
{
"user" : "admin",
"pwd": "password",
"roles" : [
{ role: "root", db: "admin" },
{ role: "readWrite", db: "admin" },
{ role: "dbAdmin", db: "admin" },
{ role: "readWrite", db: "test_db" },
{ role: "dbAdmin", db: "test_db" }
]
});
(Success...)
> db.auth("admin","password")
1
关于java - MongoDB+Java : Credentials missing in the user document,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34084344/
要在标题(或谷歌)中简洁地描述这是一个棘手的问题。我有一个分类表,其中某些列可能会根据置信度列为“已删除”。我想用“未识别”替换任何显示“已删除”的列,后跟第一列中未识别的值以行方式说“掉落”。因此,
我在 VSCode 上使用 pygame 模块,但遇到了 pygame 没有 init 成员的问题。我遵循了 this 的解决方案关联。我编辑了用户设置并添加了 "python.linting
我的问题是如何解决丢失的脚本太旧或丢失!! checking for a BSD-compatible install... /usr/bin/install -c checking whether
我正在使用带有启动器的 Spring Boot。当我错误配置启动器(缺少或定义了错误的值)时,它会打印“缺少 bean”错误消息,而不是“缺少值”。很难找到这个错误。 我的开胃菜看起来像 @Condi
我在 Django 1.7 中遇到问题,我正在尝试将用户保存到表中,但我收到一个错误,指出该表不存在。 这是我正在执行的代码: from django.conf import settings fro
我正在查看 EhCache 统计数据,我看到了这些数字: CacheMisses: 75977 CacheHits: 38151 InMemoryCacheMisses: 4843 InMemoryC
我正在尝试使用这些数据运行 lme 模型: tot_nochc=runif(10,1,15) cor_partner=factor(c(1,1,0,1,0,0,0,0,1,0)) age=runif(
我在 Microsoft Visual Studio C++ 中编写了一个程序,并为此使用了 SFML。我包含了程序所需的正确的 .dll 文件,并将它们复制到“发布”文件夹中。有效。整个程序在我的电
在设置新的Reaction CSR应用程序、一些样板库等过程中。在控制台中收到以下错误:。现在,我不会去修复一些我没有维护的包。我怎么才能找到真正的问题呢?Vite dev Build没有报告错误。
我正在上 React Native 类(class),然后使用 Flow 尝试纠正类(class)中的错误,因为讲师没有使用任何类型检查。 我在 Flow 中遇到了另一个错误,通过在互联网上进行长时间
我想删除图像标签正在寻找的缺失错误。我不想要 ult 标签占位符,试图故意将其保留为空白,直到我使用回形针浏览上传照片。 我已经将 url(:missing) 更改为许多其他内容,例如 nil 等。是
CREATE TABLE customer(customer_id NUMBER(6) PRIMARY KEY , customer_name VARCHAR2(40) NOT NULL , cust
我正在设置 invisible reCAPTCHA在我的 Web 应用程序中并且无法验证用户的响应。 (即使我传递了正确的 POST 参数) 我通过调用 grecaptcha.execute(); 以
我搜索了 these SO results找不到与我的问题相关的任何内容。我怀疑这可能是重复的。 我目前正在 .NET C# 3.5 中编写 Microsoft.Office.Interop.Exce
我在同一行收到两个错误。 Bridge *在 Lan 类中排名第一。我错过了什么? #include #include #include using namespace std; class L
首先,我看到了一些解决方案,但我没有理解它们。我是 QT 的新手,甚至谷歌也没有帮助我。英语不是我的母语 这是在QT Creator 5.6中调试后的报错信息 C2143: syntax error:
有没有办法把表1展开成表2?就是将start_no和end_no之间的每一个整数作为seq_no字段输出,取原表的其他字段组成新表(表2)。 表 1: date source market
我在 Excel (2016) 中制作了一个旭日形图,并希望为所有数据点添加标签。问题是,Excel 会自动丢弃一些标签: 似乎标签被删除是因为数据点太小或标签字符串太长。如何让 Excel 显示所有
在 R 3.0.2 中,missing() 函数可以告诉我们是否缺少形式参数。 如何避免硬编码传递给丢失的变量名称?例如在 demoargs <- function(a=3, b=2, d) {
我试图在 UI 上的某些功能中返回一个按钮,但出现了一个奇怪的错误。有人可以帮忙吗? var div = "View" 我得到的错误是: 参数列表后缺少 )。 最佳答案 onclick="javas
我是一名优秀的程序员,十分优秀!