【问题标题】:mongoose fulltext search not working猫鼬全文搜索不起作用
【发布时间】:2018-08-29 02:16:37
【问题描述】:

我在 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); });
}

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

【问题讨论】:

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


    【解决方案1】:

    请参考此链接 [1]:Best way to perform a full text search in MongoDB and Mongooseenter code hereh-in-mongodb-and-mongoose

    【讨论】:

    • 我正在使用 mlab 来存储我的数据库。它是否避免索引,我在您的示例中有相同的代码,但它不工作
    猜你喜欢
    • 1970-01-01
    • 2016-08-05
    • 2014-11-17
    • 2016-05-17
    • 2011-07-28
    • 1970-01-01
    • 1970-01-01
    • 2014-09-03
    相关资源
    最近更新 更多