BUG with reproducing instructions - Node.js driver error when using text index

I created a text index on a collection. I can query it from the MongoDB compass:

db.getCollection('test').find({$text:{$search: "apple"}})

but not from the mongodb node driver (I have the latest version, “^5.7.0”)

await db
      .collection('test')
      .find({
        $text: { $search: 'apple' }
      })
      .toArray();

It throws this error:

Error: error processing query: ns=db.usersTree: TEXT : query=hi, language=english, caseSensitive=0, diacriticSensitive=0
Sort: {}
Proj: {}
 planner returned error :: caused by :: need exactly one text index for $text query

Steps to reproduce:

  • create new collection
  • create a couple documents with a “name” field
  • create a text index on the name field
  • query it from the mongodb node.js driver

I’m using a serverless instance, which doesn’t support Atlas search, so just regular text search.

Please let me know if able to reproduce and if this will be addressed soon. Thank you

Any MongoDB staff that can confirm this bug? Seems like a pretty big problem if all node.js users can’t use text indexes

WORKAROUND:

If you create the index within Node.js, it works. To do this, temporarily disable strict mode on your connection before you run the createIndex command.

This still appears to be a bug with MongoDB but at least you won’t have to forego using the text indexes.

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.