Reputation: 195
I am trying to make a general function to find a model Object in mongoose Models, but its unable to access key from function parameters. Please help
...
findInModel: async (Model, key, value) => {
const modelObj = await Model.fineOne({ key: value });
}
...
Upvotes: 0
Views: 43
Reputation: 16127
To create a object with key is a variable, you have to use array access style.
findInModel: async (Model, key, value) => {
const query = {};
query[key] = value;
const modelObj = await Model.fineOne(query);
}
Upvotes: 1