【发布时间】:2016-04-07 08:02:15
【问题描述】:
我尝试使用这样的函数进行猫鼬查询:
/*
* @param {function} Model - Mongoose Model
* @param {String} searchText- Text that will be used to search for Regexp
* @param {String} Key- key to search into a Model
* @param {object} res - Response of node.js / express
*/
function _partialSearch (Model, searchText, key, res) {
var search = new RegExp(searchText, "i");
Model.find({ key : { $regex : search } })
.exec(function (err, docs) {
if(err) log(err);
else {
res.json(docs);
}
})
}
我的问题是查询采用参数键文字并像这样搜索:
我需要这个:
_partialSearch(Products, 'banana', 'fruts', res)
我猜到了:
Products.find({ 'fruts' : 'banana})
但我明白了:
Products.find({ key : 'banana})
【问题讨论】: