【发布时间】: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