The error seems to relate to another script (not the one you have pasted). Please check your other scripts for usage of _id and ensure your logic is correct. The following documentation provides details on how to debug and handle errors in the custom database scripts:
I figured it out dude… its because we are following the auth0 mongo integration guide that was posted a few months back but it differs from the mongo template scripts.
Auth0 should be paying me to figure out their damn bugs here.
Your getUser script needs to look like this:
function getByEmail(email, callback) {
const {MongoClient} = require("mongodb@3.1.4");
const uri = `mongodb+srv://${configuration.DB_USER}:${configuration.DB_PASSWORD}@${configuration.DB_HOST}/test?retryWrites=true`;
const client = new MongoClient(uri, { useNewUrlParser: true });
client.connect(err => {
if (err) return callback(err);
const users = client.db(configuration.DB_NAME).collection(configuration.DB_USER_COLLECTION);
users.findOne({ email: email }, function (err, user) {
if (err) return callback(err);
if (!user) return callback(null);
return callback(null, {
user_id: user._id.toString(),
nickname: user.nickname,
email: user.email
});
});
});
}
Notice how there is an added check to the template to ensure the user is not null: