0

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 });
    }
    ...

1 Answer 1

1

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);
    }
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.