0
I wrote an app that has an email verification logic and is triggered when the user makes the registration. I am using two models in Mongoose: one for users and one for authentication token. In token model I store userid:
In my Usercontroller, when the app needs to authenticate the token that was sent to the user’s email, it does so by searching the Token collection. After finding the token, it needs to fetch the userid that is in the template, according to the image above. For this I have a function User.findOne().
I would like to capture the _userid:Objectid("numberos-numeros") that is in the record, but I would like to call it within the function, more or less like this:
User.findOne({ _userID: mongoose.Schema.Types.ObjectId._userID, ref: 'Token' })
My question: is there a way to do this, identify the user in the user collection using a key that is in another collection?
Thank you!