Mongoose文本search与变音敏感

我有以下的mongoose查询:

User.find( { $text: { $search: req.query.search, $diacriticSensitive: true } }, { score: { $meta: "textScore" } }, function(err, results) { if (err) { next(err); return; } return res.json(results); }); 

查询导致以下错误信息:

 Can't canonicalize query: BadValue extra fields in $text 

当我从查询中删除“$ diacriticSensitive:true”部分时,我不会收到错误消息,但只能得到完全匹配。

我想要的是,当用户search“USERNA”,但只有用户“USERNAME”可用,这个结果也应该显示一个低分。

我正在使用Mongoose 4.3.5和MongoDB 3.0.3。

MongoDB支持这个属性,不是Mongoose支持吗?

根据文档 , $diacriticSensitive选项在mongodb v3.2启用


articles文件

 { "_id" : ObjectId("56d305dcc7ce7117db9b6da4"), "subject" : "Coffee Shopping", "author" : "efg", "view" : 5 } { "_id" : ObjectId("56d305e9c7ce7117db9b6da5"), "subject" : "Coffee and cream", "author" : "efg", "view" : 10 } { "_id" : ObjectId("56d305fec7ce7117db9b6da6"), "subject" : "Baking a cake", "author" : "abc", "view" : 50 } 

这是我的testing代码

 var ArticleSchema = new mongoose.Schema({ subject: String, author: String, view: Number, score: Number, }); ArticleSchema.index({subject: 'text'}); var article = mongoose.model('article', ArticleSchema); function queryText() { article .find({$text: {$search: 'Coffee', $diacriticSensitive: true}}, {score: {$meta: 'textScore'}}) .exec(function(err, doc) { if (err) console.log(err); else console.log(doc); }); } 

结果:

 { "_id" : ObjectId("56d305dcc7ce7117db9b6da4"), "subject" : "Coffee Shopping", "author" : "efg", "view" : 5, "score" : 0.75 } { "_id" : ObjectId("56d305e9c7ce7117db9b6da5"), "subject" : "Coffee and cream", "author" : "efg", "view" : 10, "score" : 0.75 }