【问题标题】:error connecting to MongoDB service cluster: server returned error on SASL authentication step: bad auth Authentication failed连接到 MongoDB 服务集群时出错:服务器在 SASL 身份验证步骤上返回错误:身份验证错误 身份验证失败
【发布时间】:2018-06-05 21:23:57
【问题描述】:

我正在尝试使用 Mongodb 的 Stitch 服务。 当我尝试连接到 MongoDB 时,它给了我这个错误:

执行管道时出错 com.mongodb.stitch.android.StitchException$StitchServiceException: 连接到 MongoDB 服务集群时出错:服务器返回错误 SASL 认证步骤:bad auth 认证失败。

我已经看到this 的问题,但在这里他使用登录名和密码进行身份验证,但我使用FacebookAuthProvider 进行登录。所以应该不会有bad auth的问题,因为我可以清楚地看到用户的Facebook数据。

这是我使用的代码。

        stitchClient = new StitchClient(getApplicationContext(), "user-recognition-tgnek");
        mongoClient = new MongoClient(stitchClient, "mongodb-atlas");
        db = mongoClient.getDatabase("<DatabaseName>");

        FacebookAuthProvider fbProvider = FacebookAuthProvider.fromAccessToken(AccessToken.getCurrentAccessToken().getToken());
        stitchClient.logInWithProvider(fbProvider).continueWithTask(new Continuation<String, Task<Void>>() {
            @Override
            public Task<Void> then(@NonNull Task<String> task) throws Exception {
                final Document updateDoc = new Document(
                        "owner_id",
                        task.getResult()
                );
                updateDoc.put("Name", "Deepanshu Luhach");
                return db.getCollection("Users").updateOne(null, updateDoc, true);
            }
        }).continueWithTask(new Continuation<Void, Task<List<Document>>>() {
            @Override
            public Task<List<Document>> then(@NonNull Task<Void> task) throws Exception {
                if (!task.isSuccessful()) {
                    throw task.getException();
                }
                return db.getCollection("Users").find(
                        new Document("owner_id", stitchClient.getUserId()),
                        100
                );
            }
        }).addOnCompleteListener(new OnCompleteListener<List<Document>>() {
            @Override
            public void onComplete(@NonNull Task<List<Document>> task) {
                if (task.isSuccessful()) {
                    Log.d("STITCH", task.getResult().toString());
                    return;
                }
                Log.e("STITCH", task.getException().toString());
            }
        });

这是完整的Logcat:

12-23 23:21:30.691 7086-7119/com.example.nwagh.myapplication E/Volley: [4067] BasicNetwork.performRequest:意外响应代码 502 https://stitch.mongodb.com/api/client/v1.0/app/user-recognition-tgnek/pipeline 12-23 23:21:30.705 7086-7086/com.example.nwagh.myapplication E/Stitch: 执行管道时出错 com.mongodb.stitch.android.StitchException$StitchServiceException: 连接到 MongoDB 服务集群时出错:服务器返回错误 SASL 认证步骤:bad auth 认证失败。 在 com.mongodb.stitch.android.StitchError.a(SourceFile:53) 在 com.mongodb.stitch.android.StitchClient$10.onErrorResponse(SourceFile:754) 在 com.android.volley.Request.deliverError(Request.java:598) 在 com.android.volley.ExecutorDelivery$ResponseDeliveryRunnable.run(ExecutorDelivery.java:101) 在 android.os.Handler.handleCallback(Handler.java:790) 在 android.os.Handler.dispatchMessage(Handler.java:99) 在 android.os.Looper.loop(Looper.java:164) 在 android.app.ActivityThread.main(ActivityThread.java:6515) 在 java.lang.reflect.Method.invoke(本机方法) 在 com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:440) 在 com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)

请帮我解决这个问题,我找不到与此相关的任何内容。

【问题讨论】:

  • 对于您的应用程序和集群来说,我这边一切正常。你还在看这个问题吗?如果是这样,我可以进一步查看 Atlas 集群
  • @edaniels 是的,先生,我仍然面临这个问题。这是我要实现的目标的完整代码 (https://github.com/Nikhil-Wagh/User-Recognition)。每次我尝试将某些内容插入数据库时​​都会收到此错误。
  • @edaniels link (stitch.mongodb.com/api/client/v1.0/app/user-recognition-tgnek/… Logcat 在浏览器上给出 404 page not found 错误。在日志中我的缝合应用程序(仪表板)我只能看到管道错误,其他一切正常。
  • 抱歉回复慢。我现在才收到这个通知。我不确定发生了什么,但我认为您有一个免费层集群,并且身份验证出现问题。我将尝试通过对讲机与您联系以了解后续步骤,但我想将您的集群重新链接到缝合中,以尝试解决身份验证问题。
  • @edaniels 我尝试将我的缝合应用程序与集群重新链接,并且它有效。两者之间的联系一定有问题。感谢您的建议。

标签: android mongodb authentication mongodb-stitch


【解决方案1】:

我在使用 dokku mongo:import 时遇到了同样的错误。我怀疑您在 mongo 数据库名称中包含特殊字符。 就我而言,我的数据库名称中包含点(句点)

当 'dokku mongo:create' 时,你不应该在你的 mongodb 名称中包含点我已将其更改为 seunghunlee 而不是 seunghunlee.net 现在此命令有效

dokku mongo:import seunghunlee < seunghunlee.net.dump.gz

希望对你有帮助!

【讨论】:

  • 这可能对某人有帮助。但对我来说,重新链接就像一种魅力。我的数据库名称中没有特殊字符。
【解决方案2】:

连接到 Atlas 集群 时出现一些错误。只需尝试重新链接应用与集群,一切都会完美运行。

要重新链接您的应用程序,请转到 MongoDB Atlas -> Stitch Apps -> 在 Actions 中,您将看到取消链接应用程序的选项,然后您可以重新链接它。

致谢: @edaniels

【讨论】:

    猜你喜欢
    • 2019-12-17
    • 1970-01-01
    • 2016-11-26
    • 2016-06-08
    • 2017-04-08
    • 1970-01-01
    • 1970-01-01
    • 2023-04-01
    • 1970-01-01
    相关资源
    最近更新 更多