**throw new Error(‘must provide either options.secret or both options.encryptionKey and options.signingKey’);
**
const mongoose = require("mongoose");
const encrypt = require("mongoose-encryption");
const userSchema = new mongoose.Schema({
email: {
type: String,
required: true
},
password: {
type: String,
required: true
},
createdOn: {
type: Date,
default: Date.now
}
})
const encKey = process.env.ENC_KEY;
userSchema.plugin(encrypt, {secret: encKey, encryptedFields: ['password']});
module.exports = mongoose.model("user", userSchema);
I tried using mongoose-encryption but it fails.
New contributor
Niloy Kumar Mohonta is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.