问题
I'm looking for some advice about how improve Text Search performance with MongoDB 2.6. I am also using Mongoose.
My mongoose schema has 'body: String' which contains a large chunk of XML. I ran ensureIndex which took a few minutes...
db.models.ensureIndex({ body:"text"})
I want to search this text with a user defined string.
Model.find({ $text: { $search: searchstr }},function(err,data){ });
While there are only a few thousand documents, the search will often time out ( 2 minutes+). How can I improve my performance? Thanks!
回答1:
AFAIK in general it is recomended to use the pipeline framework insted of the standard find when dealing with textSearch.
For instance doing something as:
db.model.aggregate(
[
{ $match: { $text: { $search: "text" } } },
{ $sort: { score: { $meta: "textScore" } } },
{ $limit: 10 }
]
)
Will return just the first 10 elements with much the most.
来源:https://stackoverflow.com/questions/24514894/improving-mongodb-text-search-performance