Can anyone help solve this problem? You can see it at stackoverflow. I fully explained
https://stackoverflow.com/questions/57783054/indexnotfound-text-index-required-for-text-query
Are you sure you're connected to the right database? Perhaps try running Business.listIndexes()
to confirm the index is already built?
Also, are you dropping the database before running your script?
Yes I'm pretty sure the connection is right ...
index made ...
also i tested on two separate servers and different versions of MongoDB... Node... Mongoose... etc.
I tested it with all kinds of third party software and run text query.
I ran exactly the same query in MongoDB compass and it was running correctly without error.
I updated the stack post:
EDITED: this error does not occur when this query has a result! Only occurs when the query result is null.
I even got this result.
I had never encountered such a problem before, and it really got into trouble.
I have two document in Business Collection >>
Doc 1
{
"_id" : ObjectId("5d6f69f25f7e0e20dc9434d6"),
"name" : "google"
}
Doc 2
{
"_id" : ObjectId("5d6f6b506aae4f24ac994711"),
"name" : "amazon"
}
For example, when I search on google or amazon it does without error,
But this error occurs when I search anything else.
Errr.stack:
{ MongoError: text index required for $text query
at Connection.<anonymous> (C:\Users\Desktop\Projects\backend\node_modules\mongodb-core\lib\connection\pool.js:443:61)
at Connection.emit (events.js:198:13)
at processMessage (C:\Users\Desktop\Projects\backend\node_modules\mongodb-core\lib\connection\connection.js:364:10)
at Socket.<anonymous> (C:\Users\Desktop\Projects\backend\node_modules\mongodb-core\lib\connection\connection.js:533:15)
at Socket.emit (events.js:198:13)
at addChunk (_stream_readable.js:288:12)
at readableAddChunk (_stream_readable.js:269:11)
at Socket.Readable.push (_stream_readable.js:224:10)
at TCP.onStreamRead [as onread] (internal/stream_base_commons.js:94:17)
ok: 0,
errmsg: 'text index required for $text query',
code: 27,
codeName: 'IndexNotFound',
name: 'MongoError',
[Symbol(mongoErrorContextSymbol)]: {} }
What is the output of Business.listIndexes()
before running your query?
Also, you didn't answer this question: are you dropping the database before running your script?
output of Business.listIndexes() :
[
{ v: 2,
key: { _fts: 'text', _ftsx: 1 },
name: 'name_text_family_text',
ns: 'Test.users',
background: true,
weights: { family: 1, name: 1 },
default_language: 'english',
language_override: 'language',
textIndexVersion: 3
}
]
About dropping the database you mentioned, Yes I dropped the database but the problem didn't solved.
Something unusual happened
I was not there for a while and had not worked on the problem, and to this day my system was inactive,
But unbelievably this problem has been fixed!
Without any changes to the code or database.
So, to use that $text feature, need to drop database? I dont understand that error, it resolves and comes back again
@brunoqs no, you do not need to drop the database. You need to wait for the index to finish building before using $text
.