S
S
Stanislav2019-07-09 13:55:30
MongoDB
Stanislav, 2019-07-09 13:55:30

Why is the request being executed for more than 3 seconds?

There are documents like

{
    _id: ...,
    description: " slovo slovo2 slovo3 ...."
}

In the description field, I drop all the text by which the document can be found
. For this field, I created an index. I make a simple selection .
db.collection.createIndex({ description: "text" })
return Collection.find({
    $text: { $search: "slovo slovo2" }
}).limit(10)

This query is relatively fast, in just 60ms
But I also need to do the sorting, calculate the "weight of the document" and sort them, so I do the following
return Collection.find(
    { $text: { $search: "slovo slovo2" } },
    { score: { $meta: "textScore" } }
).limit(10)

Now the query completes in more than 3 seconds, why is that? Maybe you need to create some other index for score? Although I tried and did not help... (db.collection.createIndex({score: 1}))

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question