mongoose全文搜索无法正常工作

时间:2018-03-20 10:05:39

标签: node.js search mongoose full-text-search

我的mongoose索引有问题 我的模特



var mongoose = require("mongoose");

var Schema = mongoose.Schema; 


var commentSchema = new Schema({
   
    customer_id: String,
    motel_id: String,
    customer_name: String,
    content: String,
    created_at: Date


});
commentSchema.set('autoIndex', false);
commentSchema.index(
    {'$**': 'text'}
)

var comments  = mongoose.model("comments", commentSchema);




和我的搜索功能



function testIndex(req, res) {
    var searchString = "h";
    comment.find({$text: {$search: searchString}})
    .skip(20)
    .limit(10)
    .exec(function(err, docs) { res.send("docs:" + docs); });
}




但它不会返回任何价值。我该如何解决这个问题?

1 个答案:

答案 0 :(得分:0)

请参阅此链接   [1]:Best way to perform a full text search in MongoDB and Mongoose enter code here h-in-mongodb-and-mongoose

相关问题