0

i have a problem with index in mongoose My model

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);

and my search function

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

but it don't return any value. How can i fix this problem?

mintquan
  • 157
  • 3
  • 16

1 Answers1

0

Please refer this link [1]: Best way to perform a full text search in MongoDB and Mongooseenter code hereh-in-mongodb-and-mongoose

Prakash Jethava
  • 200
  • 1
  • 7
  • i'm using mlab to store my db. Does it avoid indexes, i have the same code in your example but it's not working – mintquan Mar 21 '18 at 02:17