User collection is created in mongoDB when user sign up on page with all the information except array fields. After login the user fills one form and submit the data. Those datas I want to store in 'User' collection array i.e. Addtasks as you can see in schema. How to achieve that?
var userSchema = new mongoose.Schema({
email: {
type: String,
unique: true,
required: true
},
name: {
type: String,
required: true
},
hash: String,
salt: String,
Addtasks : [{
topic: String,
words: Number,
keywords: String,
website: String,
otherdetails: String,
exampleRadios: String
}]
});
userSchema.methods.setPassword = function(password) {
this.salt = crypto.randomBytes(16).toString('hex');
this.hash = crypto.pbkdf2Sync(password, this.salt, 1000, 64, 'sha1').toString('hex');
};
userSchema.methods.validPassword = function(password) {
var hash = crypto.pbkdf2Sync(password, this.salt, 1000, 64, 'sha1').toString('hex');
return this.hash === hash;
};
module.exports = mongoose.model('User', userSchema);