S
S
squadbrodyaga2020-11-03 12:41:15
Node.js
squadbrodyaga, 2020-11-03 12:41:15

How to get user _id during registration (mongoose)?

Hello, I want to make sure that each user has their own referral link,
which will be equal to the _id of this user, but I can’t figure out how to do it, this is how I imagine it:

This is how the user scheme looks like (this is not a link, this is a spoiler)

UserSchema
const userSchema = new Schema({
    login: {
        type: String,
        required: true
    },
    email: {
        type: String,
        required: true
    },
    password: {
        type: String,
        required: true
    },
    reflink: {
        type: String,
        required: true
    },
})

And this is how I register a new user and I can’t figure out how to make reflink: be equal to _id
const user = new User({ 
       login: login,
       email: email,
       password: password,
       reflink: _id
})
await user.save()

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question