1

I am trying to use the Stitch service by Mongodb. When I try to connect to MongoDB, it gives me this error :

Error while executing pipeline com.mongodb.stitch.android.StitchException$StitchServiceException: error connecting to MongoDB service cluster: server returned error on SASL authentication step: bad auth Authentication failed.

I have already seen this question, but here he was using login and password for authentication but I'am using FacebookAuthProvider for login. So there shouldn't be any issue of bad auth, as I can clearly see the users Facebook data.

This is the code I used for the same.

        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());
            }
        });

This is the complete Logcat:

12-23 23:21:30.691 7086-7119/com.example.nwagh.myapplication E/Volley: [4067] BasicNetwork.performRequest: Unexpected response code 502 for 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: Error while executing pipeline com.mongodb.stitch.android.StitchException$StitchServiceException: error connecting to MongoDB service cluster: server returned error on SASL authentication step: bad auth Authentication failed. at com.mongodb.stitch.android.StitchError.a(SourceFile:53) at com.mongodb.stitch.android.StitchClient$10.onErrorResponse(SourceFile:754) at com.android.volley.Request.deliverError(Request.java:598) at com.android.volley.ExecutorDelivery$ResponseDeliveryRunnable.run(ExecutorDelivery.java:101) at android.os.Handler.handleCallback(Handler.java:790) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loop(Looper.java:164) at android.app.ActivityThread.main(ActivityThread.java:6515) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:440) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)

Please help me with this issue, I can't find anything related to this.

Nikhil Wagh
  • 1,376
  • 1
  • 24
  • 44
  • Things look okay on my end for your app and cluster. Are you still seeing this issue? If so, I can look in further to the Atlas cluster – edaniels Dec 29 '17 at 22:08
  • @edaniels Yes sir, I'm still facing the issue. Here is the complete code for what I'm trying to achieve ([https://github.com/Nikhil-Wagh/User-Recognition](https://github.com/Nikhil-Wagh/User-Recognition)). I get this error everytime I try to insert something into the DB. – Nikhil Wagh Dec 31 '17 at 04:23
  • @edaniels The [link](https://stitch.mongodb.com/api/client/v1.0/app/user-recognition-tgnek/pipeline) (https://stitch.mongodb.com/api/client/v1.0/app/user-recognition-tgnek/pipeline)in the Logcat gives a 404 page not found error, on the browser. And in the log my stitch app (dashboard) I can see error with pipeline only, everything else is working. – Nikhil Wagh Dec 31 '17 at 19:45
  • 1
    Sorry for the slow response. I just got this notification now. I'm not exactly sure what happened but I think you have a free tier cluster and something with the authentication went wonky. I'll try to follow up with you on intercom regarding next steps but I'd like to relink your cluster into stitch as an attempt to fix the auth issue. – edaniels Jan 01 '18 at 05:09
  • @edaniels I tried to relink my stitch application with cluster and it worked. Something must have went wrong with the connection between the two. Thanks for the suggestion. – Nikhil Wagh Jan 01 '18 at 11:48

2 Answers2

1

There was some error with connection to Atlas cluster. Just try to relink the app with the cluster and everything will work perfectly.

To relink your app go to MongoDB Atlas -> Stitch Apps -> In the Actions you will see the option to unlink the app, then you can relink it again.

Credits: @edaniels

Nikhil Wagh
  • 1,376
  • 1
  • 24
  • 44
0

I had the same error when using with dokku mongo:import. I am suspecting that you included special characters in your mongo db name. In my case I included dot(period) in my db name

You shouldn't include dot in your mongodb name when 'dokku mongo:create ' I've changed it to seunghunlee instead of seunghunlee.net now this command works

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

Hope it helps!

  • 1
    That may help someone. But for me relinking worked like a charm. There was no special character in my db names. – Nikhil Wagh Feb 08 '19 at 06:11