Auth0 Home Blog Docs

Auth0 Tutorials: Using MongoDB Atlas as a Custom Database

In this article, you will learn how to use MongoDB Atlas as a custom database in your Auth0 account.

Brought to you by @bruno.krebs :man_technologist:t5:

Read on :dart: >> https://auth0.com/blog/auth0-tutorials-using-mongodb-atlas-as-a-custom-database

Quite easy to integrate these great services together, right? Let me know your thoughts.

Hi,

Thank you for your tutorial. I was able to implement all the custom functions except one. In “create”, I’m getting an “User not found” error. This looks counter-intuitive, as users are not expected to be found before sign up. Further, I cannot log anything, when I can with any other custom functions. Could you please advise? Let me know if you need any other information.

image

image

Adding to my previous comment, it seems like when I call create(), I’m unknowingly calling getByEmail(). The “User not found” error was coming from getByEmail() based on my experiment using console.logs.

Sorry for the spam, but just wanted to give you an update. I’ve wiped out getByEmail(), and now create() works for the first time. I can resort to not using getByEmail() and updating the logic for changePassword() to check an user exists; however, it would still be great if you could update the guide for future references.

hi, @quizapp6781. Sorry for the delay. So, you solved your problem by not using the “Get User” script? I will have to double check this to see if there is a problem on the article instructions.

Hi @bruno.krebs. No problem!

Yes, I could sign up users by not using the “Get User” script. I realized that the “Get User” script is called when I call “Sign up”. Auth0 could not, of course, “Get User” when the user still hasn’t signed up yet (and thus not in the database).

1 Like

I see, thanks for letting us know.

Hi, @quizapp6781. I think I know what the problem is. Let me see if I get this right:

You probably started reading the article at the very top and implementing the version of the integration that migrates users to Auth0, right? Then, following the article, you switched to the alternative that does not migrate users. However, instead of replacing the Get User script with the one showed on this section, you probably kept the old one there.

If you did that (and the message you were getting makes me believe you did), then that was the problem.

Although subtle, there is a difference on both scripts. The first one contains the following conditional:

if (!user) return callback("User not found.");

The second one contains the following:

if (!user) return callback(null);

This difference allows the Create script (sign up) to keep moving if there is no user on the database. Oh, and to make things a bit clearer. This works like that because Auth0 wants to check if the user that is trying to sign up already exists on your database (to avoid duplicates). That is, the Create script calls the Get User script to make this validation.

Let me know if that helps and solves your problem.

Great tutorial. It works just fine.

But shouldn’t it save the passwords with a bcrypt hash?