I want to create a json object according to function parameters but it takes the parameters as a string.
userSchema.statics.updated = async function (_id, field, value) { // it does not take that params
const user = await this.updateOne({ _id }, { $set: { field: value } }); //!!!!
};
The field parameters is a json field that i create like name,age... But it always create and object like
{"field":value}
how can i fix it?
Json structure example:
{
"email": "",
"password": "",
"surname": "",
"name": "",
"nickname": "",
"birthdate": ""
}
{ [field]: value }if I understand correctly. The key must be dynamic, but right now you're marking it explicitly asfield.