Continue Discussion 25 replies
December 2020

konrad.sopala Community Engineer

Any MongoDB users out there! Whoop whoop!

August 2022

vlal080

I’m having issues deleting a user in the mongodb database.
“[Error] Password contains an illegal unescaped character” I get this error

1 reply
August 2022 ▶ vlal080

thameera

@vlal080 It’s likely that you might need to URL-encode the password, as described here: mongodb - Mongo DB Connection - Password contains unescaped characters - Stack Overflow

August 2022

vlal080

How do I URL-encode the password.

1 reply
August 2022

dan-auth0 Auth0 Employee

Howdy! :wave: Thanks for reading this blog post!

You can consult this document from MongoDB on how to handle special characters in your connection string:

Only a handful of special characters need conversion to percent encoding:

: / ? # [ ] @

Look for this note in the document:

image
t

There’s a link in there that takes you to a resource where you can learn how to convert the special characters

December 2022

shaun1

Hey guys, I keep getting an error that states:

[MongoError] 354 - The server is being accessed through a load balancer, but this driver does not have load balancing enabled

When trying to use a script given (login, get user, etc) this is what appears. If I change my mongodb URI slightly it still appears, telling me that it may not be my database that is causing the issue. Any help will be greatly appreciated

June 2023

AdmiralBot

hey I am facing this error when I try to run any of the code snippets : Unsupported OP_QUERY command: find. The client driver may require an upgrade. For more details see https://dochub.mongodb.org/core/legacy-opcode-removal.
I have the latest version of Mongo and Mongoose installed what do I need to do it get rid of this issue

1 reply
June 2023

samarjit.ghosh

Getting the same error with latest mongodb

July 2023 ▶ AdmiralBot

softbytes

I have the same issue. I think auth0 node.js runtime missing latest drivers for mongodb.

August 2023

bajcmartinez Auth0 Employee

Hi @softbytes @samarjit.ghosh @AdmiralBot,

For the MongoDB drivers its correct that the default version is 3.10, which is not compatible with MongoDB versions 4.5+, with that said, you can opt to use other drivers in your code by changing the way you initialize the MongoClient.

If you are using MongoDB v5, or v6, please replace in your scripts code the version of the MongoDB drivers to 4.1.0, after that your scripts should work.

Here is an example on how to get an updated MongoClient:

const MongoClient = require('mongodb@4.1.0').MongoClient;

Hope that helps, and if you have any further questions please let me know.

I’ll keep an eye on this thread to make sure I can give answers on time.

September 2023

kristina71103

I got always error [SandboxUnhandledError] Cannot find module ‘mongodb@3.1.4’ Require stack: - /data/io/node18/5545297c-fce7-45b0-8203-c5362087a6b8/webtask.js

1 reply
September 2023 ▶ kristina71103

bajcmartinez Auth0 Employee

Hi @kristina71103, welcome to the Auth0 Community.

In your code, try to initialize the MongoClient with the following code instead:

const MongoClient = require('mongodb@4.1.0').MongoClient;

And please let me know if that solves your issue. Thanks

2 replies
September 2023 ▶ bajcmartinez

kristina71103

Thanks for your answer, but it doesn’t help
Now I have this message:
Cannot find module ‘mongodb@4.1.0’ Require stack: - /data/io/node18/2a8d55de-a9d5-440e-b771-2554fdfe1f47/webtask.js

1 reply
September 2023 ▶ kristina71103

bajcmartinez Auth0 Employee

Hi, I see… may I ask which database action script are you working on? have you used the templates we provide? For example:

The templates will preload the code for you, and you should adjust the mongodb version as I sent in my previous message, and of course your connection details.

September 2023

kristina71103

I tried to repied how it was in tutorial to connect Auth0 to MongoDB, and when i try use create script, i got this message. i have a cluster in MongoDB with db db-name.users


September 2023

imveeru

I’ve been facing the same error. Any solutions?

September 2023 ▶ bajcmartinez

imveeru

I’ve tried this. It’s still showing the same error.

1 reply
September 2023 ▶ imveeru

taitheexplore

I also got the same issue

1 reply
September 2023 ▶ taitheexplore

bajcmartinez Auth0 Employee

hi @taitheexplore @kristina71103, I’ve routed this internally as I don’t have an immediate answer, but I’ll get back to you soon.

Thanks

September 2023

buddhins

I also got same error, cannot find any solution for this, what we can do? Below mentioned fully detailed error stack from Webtask Logs.

September 2023

marialena

Hello everyone, facing the exact same issue here:

[SandboxUnhandledError] Cannot find module ‘mongodb@3.1.4’
Require stack: - /data/io/node18/5777205b-486a-478a-a40a-e11cbb127480/webtask.js

I tried the alternatives mentioned above but none of them work for my case as well. Is there any updates ?

September 2023

bajcmartinez Auth0 Employee

Hi @marialena @buddhins @taitheexplore,

The issue seems related to the version of NodeJS you are running in your tenant (you can check your version here: https://manage.auth0.com/#/tenant/advanced).

The following versions of mongodb drivers are available for the following NodeJS versions:

If you want to check other packages or other versions of node, please check out the following page:

https://auth0-extensions.github.io/canirequire/

By adjusting the right mongo driver to match your tenant’s NodeJS version your issue gets fixed.

Thanks

1 reply
September 2023 ▶ bajcmartinez

buddhins

Thank you @bajcmartinez . Error fixed. In my tenant, it used Node 18, then I changed it to NodeJS 16 and import mongodb version 4.1.0 version (const MongoClient = require(‘mongodb@4.1.0’).MongoClient;). Now it works without any error.

1 reply
September 2023 ▶ buddhins

bajcmartinez Auth0 Employee

That’s great @buddhins, thanks for replying back with the confirmation. I’ll make changes on the article so that this topic is address.

Have a great day!

June 2024

dmitry

Posting this information everywhere that I see Node 18 and people rolling back to 16.

Auth0 Engineering replied to my inquiry and responded with this:

To use version 5 of the mongo driver, you should update your script to use promises. Here’s an example get_user script you can reference.

function getByEmail(email, callback) {
  const MongoClient = require('mongodb').MongoClient;
  const client = new MongoClient(configuration.URL);
  
  (async () => {
    try {
      await client.connect();
      
      const db = client.db(configuration.DB);
      const users = db.collection('users');
      
      const user = await users.findOne({ email: email });
      if (!user) return callback(null, null);
      
      return callback(null, {
        user_id: user._id.toString(),
        nickname: user.nickname,
        email: user.email
      });
    } catch(e) {
      return callback(e);
    } finally {
      await client.close();
    }
  })();
}

I can confirm this works and fixes the problem. I’m able to use latest Mongo 5.x client and Node 18.