我尝试在MongoDB中为Node.js动态构建查询。创建它的函数是:
app.set('searchTerm', function (field, str){
var i, searchTerm, keywords;
keywords = str.split(' ');
searchTerm = {field : str , _keywords : keywords};
return searchTerm;
});
我的问题是构造的对象最终会出现字符串'字段'作为关键,而不是传递的论点。如何评估论证?
答案 0 :(得分:2)
app.set('searchTerm', function (field, str){
var i, searchTerm, keywords;
keywords = str.split(' ');
searchTerm = {_keywords: keywords};
searchTerm[field] = str;
console.dir(searchTerm);
return searchTerm;
});