I am struggling with a MongoDB query. The records' structure is really easy:
{ body: "Some sentence, no more than 4-5 lines I would say", title: "Just some characters", date: "2021-10-17 11:11:11" }
By now we have 800k records. When searching for uncommon words, the search is very very quick and results are given just after some ms, as expected. However, if using very common words, which may appear even in the most of records, the search itself can take up to 15 seconds.
The code I use is:
var queryString = "aVeryCommonWord";
db1.collection("nic_news").createIndex({
title: "text",
body: "text"
})
query = {
$text: {
$search: queryString
},
date: {
$gt: "2021-10-17"
} ,
}
var skipInt = 0;
db1.collection("nic_news").find(query).skip(skipInt).sort({
date: -1
}).limit(25).toArray(function (err, doc) {
...
Even if I limit the results by number and date, like in the code above, I got no less than 15 seconds to see results in console.
Any idea on how to optimize this search?
Thank you very much!