'TypeError: Cannot read properties of undefined (reading 'forEach') - mongoose encrypt

I'm study authentication and security, and when I started to use encypto to some data fields in the server, this error appears. I tried many ways to fix it, but still unsuccessfull. Please help.

here is the code:

mongoose.connect("mongodb://localhost:27017/userDB", { useNewUrlParser: true })

const userschema = new mongoose.Schema({
    email: String,
    password: String
});


const secret = "secretKey";
userschema.plugin(encrypt, { secret: secret, encryptedFields: ['password'] });

const User = mongoose.model('User', userschema);

The terminal says the error is in:

userschema.plugin(encrypt, { secret: secret, encryptedFields: ['password'] });

Help :)



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source