Hello! There is a mongo collection of the following type
const GroupsShema = new Schema({ name: { type: String, required: [ true, 'Укажите название группы'] }, groupInvite: { type: String, required: [ true, 'Укажите инвайт группы'] }, users: [ { author: { type: String }, role: { type: String }, token: { type: String }, login: { type: String, }, hash: String, salt: String } ] }); GroupsShema.methods.setPassword = function (password) { this.users.salt = crypto .randomBytes(16) .toString('hex'); this.hash = crypto .pbkdf2Sync(password, this.users.salt, 1000, 512, 'sha512') .toString('hex'); }; GroupsShema.methods.validPassword = function (password) { var hash = crypto .pbkdf2Sync(password, this.users.salt, 1000, 512, 'sha512') .toString('hex'); return this.users.hash === hash; }; The task is to find a group in which there is a user from users by the invite group (the groupInvite field), and then in this group to find the user by login and token and fill in the remaining fields (that is, update the fields in 1 users document. + Second the problem is that the setPassword and validPassword methods are not working, it’s all darkness, how to describe them, so that they are applied specifically to the users document, and not the groups.
Your ideas?