I try make a mongoose query using a function like this:
/* * @param {function} Model - Mongoose Model * @param {String} searchText- Text that will
You can't directly use a variable as an object key like that, but assuming you're using Node.js 4.0 or above, you can use its ES6 support for computed property names to do this by surrounding key in brackets:
key
Model.find({ [key] : { $regex : search } })