There is a collection, you need to do a search in it. To do this, you need to create an index, which will then be used to search. The problem is that through the console I can create it:
db.films.createIndex({"title":"text", "stars":"text"}) But in express'e I just can not. Here is the server code:
router.post('/find', function(req, res, next) { Film.createIndex({ "title": "text" }); Film.find({ $text: { $search: "war" } }, { score: { $meta: "textScore" } }, function(err, docs) { if (err) { console.log(err) } console.log(docs) }) }); When I run this code, I get an error 500 into the console . Tell me, where did I make a mistake?
I already figured out the error, "index is not a function". But now another problem, I can not create the required index through the schema (model). Tried so
var filmSchema = new Schema( { title: { type: String, index: true }, releaseYear: Number, format: String, stars : { type: String, index: true } }); But with this way, at the output I get the wrong index that I need (i.e., the way I create manually via the command line)
filmSchema.index({title: 1, start: 1}), if I remember correctly - nörbörnën