Answer the question
In order to leave comments, you need to log in
How to do an adequate text search in MongoDB?
Hello, I'm doing a search on express + mongoose.
There is a schema and setting indexes:
var postSchema = mongoose.Schema({
access: Boolean,
readed: Boolean,
title: String,
num: Number,
tags: [String],
text: String,
author: {
idNum: Number
},
addtime: String,
comments: [],
reviews: Number
});
postSchema.plugin(require('mongoose-paginate'));
postSchema.index({ title: 'text', tags: 'text', text: 'text'});
{
"_id" : ObjectId("54beaa0a73ddc8e822708cd3"),
"addtime" : "20.1.2015",
"reviews" : 0,
"readed" : true,
"text" : "SomeTagSomeTagSomeTag",
"num" : 2,
"title" : "SomeTagSomeTag",
"access" : true,
"comments" : [],
"author" : {
"idNum" : 1
},
"tags" : [
"SomeTag"
],
"__v" : 0
}
Post.paginate({'access':true, 'text':{'search':req.body.call}}, req.query.page, req.query.limit, callback);// тут я все писать не буду, не важно дело.
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question