连接到MongoDB服务群集时出错:服务器在SASL身份验证步骤上返回错误:错误的身份验证身份验证失败

时间:2017-12-23 18:07:08

标签: android mongodb authentication mongodb-stitch

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

  

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

我已经看到了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身份验证步骤:错误的身份验证身份验证失败                                                                              在com.mongodb.stitch.android.StitchError.a(SourceFile:53)                                                                              在   com.mongodb.stitch.android.StitchClient $ 10.onErrorResponse(的SourceFile:754)                                                                              at 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)                                                                              at java.lang.reflect.Method.invoke(Native Method)                                                                              在   com.android.internal.os.RuntimeInit $ MethodAndArgsCaller.run(RuntimeInit.java:440)                                                                              在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)

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

2 个答案:

答案 0 :(得分:0)

Atlas群集的连接存在一些错误。只需尝试重新链接应用程序与群集,一切都将完美。

要重新链接您的应用,请转到 MongoDB地图册 - &gt; 针迹应用 - &gt;在操作中,您会看到取消关联应用的选项,然后您可以重新重新链接。

致谢: @edaniels

答案 1 :(得分:0)

与dokku mongo:import一起使用时,我遇到了相同的错误。我怀疑您在mongo数据库名称中包含特殊字符。 在我的情况下,我在数据库名称中包含了点(句点)

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

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

希望有帮助!