7

I have got a serverless db on atlas (https://www.mongodb.com/serverless). I used the connection string recommended by ATLAS:

mongodb+srv://<username>:<password>@xyz.esxbh.mongodb.net/myFirstDatabase?retryWrites=true&w=majority

however as soon as i try to create a record, i get the following error:

{"errorType":"Runtime.UnhandledPromiseRejection","errorMessage":"MongoParseError: Text record must only set `authSource` or `replicaSet`","reason":{"errorType":"MongoParseError","errorMessage":"Text record must only set `authSource` or `replicaSet`","name":"MongoParseError","stack":["MongoParseError: Text record must only set `authSource` or `replicaSet`","

I don't think that the connection string is correct, on the other hand the dns entry for the server does reply with 2 servers.

I tried dropping the '+srv' part, however in that case the save function from mongoose just hangs forever timing out the lambda function.

I could not find any similar problem on google.

The TXT entry record from the dns server shows:

"TXT    "authSource=admin&loadBalanced=true"

How have you configured the serverless database to work?

The code that generates the error depends on mongoose and is as follows:

        try {
          const customer = new Customer(cust);
          console.log('new cusotmer created');
          const returnedCustomer = await customer.save();
          console.log(returnedCustomer);
          return serverResponse(200, returnedCustomer);
        } catch(err){
          console.log(err);
          return errorHandler(500, err)
        }

It seems that the connection to the database is fine:

try {
    await dbTools.connectMongoose();
    console.log('*** connected ***');

} catch(err){
    console.log('error when connecting');
    return errorHandler(500, err);
}

Now, looking at the source code, nothing really too complicated:

if (Object.keys(record).some(key => key !== 'authSource' && key !== 'replicaSet')) {
  return callback(
    new MongoParseError('Text record must only set `authSource` or `replicaSet`')
  );
}

I am now really struggling to understand what's wrong as authSource seems to be present in the TXT record.

5
  • The actual connection string looks fine, what line of the code generates this error? Commented Aug 1, 2021 at 9:54
  • remove loadBalanced=true from TXT record. Commented Aug 1, 2021 at 10:27
  • Hey thanks for both answers. I cannot remove loadBalanced=true as this is a service provided by atlas. re- the code that generates the error, it's a simple mongoose save() function: try { const customer = new Customer(cust); console.log('new cusotmer created'); const returnedCustomer = await customer.save(); console.log(returnedCustomer); return serverResponse(200, returnedCustomer); } catch(err){ console.log(err); return errorHandler(500, err) } Commented Aug 3, 2021 at 6:58
  • @ArbazSiddiqui I think your solution is right, problem is I don't control the server's dns Commented Aug 3, 2021 at 20:22
  • I am having the same issue now Commented Feb 22, 2024 at 13:05

3 Answers 3

11

Upgrading mongoose to the latest version worked for me in Nodejs.

  1. Remove "mongoose" from package.json.
  2. Reinstall "npm i mongoose"
  3. "mongoose version 6.0.5" should work.

Worked on 10-Sep-2021

Sign up to request clarification or add additional context in comments.

2 Comments

Yeah, It is working well. Thanks for your answer, I was also having same issue and you saved me in that.
Glad to learn that I helped you :)
1

For anyone still experiencing this in 2022, here is an answer from a MongoDB employee (at the bottom). It's a native Node.js driver issue (nothing to do with AWS lambda specifically), which will waterfall to all ODM implementations that implement the native driver.

https://www.mongodb.com/community/forums/t/atlas-serverless-and-dns-txt-record/117967/9

According to Zia Ullah's answer to this same question, this is fixed by Mongoose 6.0.5.

Comments

0

If you are getting this error while using mongoimport or another item of mongodb-database-tools, then upgrade your tools to version 100.5.x or later

for mac: brew upgrade mongodb-database-tools

https://www.mongodb.com/docs/atlas/reference/serverless-instance-limitations/

https://www.mongodb.com/docs/database-tools/installation/installation-macos/

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.