Connecting Auth0 to MongoDB

Configure MongoDB as an Auth0 custom database to simplify user migration or just add OAuth/Open ID Connect.
Read more…

Brought for you by @bendechrai

1 Like

Any MongoDB users out there! Whoop whoop!

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.

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

@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

How do I URL-encode the password.

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

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

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 Like

Getting the same error with latest mongodb

1 Like

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

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.

2 Likes

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

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

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

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.

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


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

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

2 Likes