string不能使用$ text

这段代码被转储为exception

self.staticVars.Model .find({shortAddress: {$text : { $search: data.text }}, _town: data._town},{limit: 10}) .populate('_street _district') .sort({house: 1}) .exec(callback); 

例外

 Can't use $text with String 

模型

 shortAddress: { type: String }, 

指数

 collection.ensureIndex({fullAddress: 'text', shortAddress: 'text'}, { default_language: "russian" },function(){}); 

看看文档,你不能指定一个字段的文本search,它会search所有索引字段,所以在你的情况下,它将searchfullAddress和shortAddress返回匹配在这些字段中的任何一个的文档。

您的查询将需要是:

 self.staticVars.Model .find({$text : { $search: data.text }, _town: data._town},{limit: 10}) .populate('_street _district') .sort({house: 1}) .exec(callback); 

这现在应该返回你正确的数据。