mongodb / stitch-js-sdk

MongoDB Stitch JavaScript SDK
Apache License 2.0
113 stars 67 forks source link

Mongo DB access issue #126

Closed jd048 closed 6 years ago

jd048 commented 6 years ago

When i am accessing database in my application it will give me below error. Error: error connecting to MongoDB service cluster: server returned error on SASL authentication step: bad auth Authentication failed. i am just doing CRUD operations.

POST https://stitch.mongodb.com/api/client/v1.0/app/xxxxxxxx/pipeline 502 () error connecting to MongoDB service cluster: server returned error on SASL authentication step: bad auth Authentication failed.

let appId = 'XXXX'; let client = new stitch.StitchClient(appId); const db = client.service('mongodb', 'mongodb-atlas').db('JXXX'); client.login().then(() => db.collection('test').updateOne({ owner_id: client.authedId() }, { $set: { message: 42 } }, { upsert: true }) ).then(() => db.collection('test').find({ owner_id: client.authedId() }).limit(100).execute() ).then(docs => { console.log("Found docs", docs) console.log("[MongoDB Stitch] Connected to Stitch") }).catch(err => { console.error(err) });

edaniels commented 6 years ago

HI @jd048,

I see you're using the v1.0 API. Could you upgrade your JS SDK to the latest 3.0.x version? After that, I think you'll need to email me your Atlas Group/Project ID and App ID so that I can see if your atlas cluster is properly linked. It looks like the user that Stitch uses may have been deleted.

My email is erd@mongodb.com

ravichandranjv commented 6 years ago

Hi @edaniels

I have a similar issue but with a SCRAM SHA 1 Atlas error (Is this the right place to seek an answer if not, I will remove this comment) with my stitch app. Running nodejs latest, mongo shell 3.0 (Edited: cannot upgrade to 3.2 as 32 bit OS). The Db object is output after the client.login

 clientPromise.then(client => {
        const db=client.service('mongodb', 'mongodb-atlas').db('whatflix');
        //console.log(db)
        client.login().then(()=>{
         //db.collection('test').insert(newJsonData).then((result)=>{
             console.log(db)
          db.collection('test').find({}).limit(1).execute().then(docs => {

image

image

And if username, pw is supplied as parameters to the login method

stitchClient.login("whatflix-user", "xxx");

then the error is "unsupported"

image

ravichandranjv commented 6 years ago

Error resolved. It was due to IP not whitelisted. Dynamic IPs need to be updated constantly.

A 0.0.0.0 IP to allow any connection may help if a threshold can be set to the IP in Atlas, for example, Max connections to be allowed from anywhere - 5 or 10 and max data - 40 MB or something?

edaniels commented 6 years ago

Glad you got it resolved.