我正在尝试使用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:https://stitch.mongodb.com/api/client/的意外响应代码502 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.andong.bol.Revid上的com.andong.b上的com.mongodb.stitch.android.StitchClient $ 10.onErrorResponse(SourceFile:754)中的com.mongodb.stitch.android.StitchError.a(SourceFile:53) . (Request.java: 598)在com.and.volley.ExecutorDelivery $ ResponseDeliveryRunnable.run(ExecutorDelivery.java:101)android.os.Handler.handleCallback(Handler.java:790)android.os.Handler.dispatchMessage(Handler.java:99) )位于android.app.Looper.loop(Looper.java:164)的android.app.ActivityThread.main(ActivityThread.java:6515),位于com.android的java.lang.reflect.Method.invoke(Native Method) . com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)中的internal.os.RuntimeInit $ MethodAndArgsCaller.run(RuntimeInit.java:440)
请帮我解决这个问题,我找不到与此有关的任何内容 .
1 回答
与Atlas集群的连接存在一些错误 . 只需尝试使用群集 relink 应用程序,一切都将完美 .
要重新链接您的应用程序,请转到 MongoDB Atlas - > Stitch Apps - >在 Actions 中,您将看到取消链接应用程序的选项,然后您可以再次重新链接它 .
Credits: @edaniels