When using text index in node.js driver, error: "need exactly one text index for $text query"

I created a text index on a table “users” on a field “name”. The shell command “getIndexes” returns the following:

{
    v: 2,
    key: { _fts: 'text', _ftsx: 1 },
    name: 'name_text',
    sparse: true,
    weights: { name: 1 },
    default_language: 'english',
    language_override: 'language',
    textIndexVersion: 3
  }

I’m confused why the following query gives me the error:
MongoServerError: 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
I do not have multiple text indexes on my collection – just one.

This is exactly what my input is:

const searchRes = db
      .collection('users')
      .find({ $text: { $search: 'hi' } });

Which is exactly what the documentation says to do

More details: I’m using serverless so Atlas Search is not supported, so I’m doing a self-managed deployment (using SST). This query works perfectly well in my mongoDB Compass shell, just not from my node.js driver.

Thank you for your time!

When I run “getIndexes()” on the users collection, it prints the following (just to show I don’t have multiple text indexes):

[
  { v: 2, key: { _id: 1 }, name: '_id_' },
  { v: 2, key: { email: 1 }, name: 'email_1', unique: true },
  {
    v: 2,
    key: { oauthId: 1 },
    name: 'oauthId_1',
    unique: true,
    sparse: true
  },
  {
    v: 2,
    key: { _fts: 'text', _ftsx: 1 },
    name: 'name_text',
    weights: { name: 1 },
    default_language: 'english',
    language_override: 'language',
    textIndexVersion: 3
  }
]

Additionally, I tested deleting the index, then running the query to see what the error is, and the error is accurate: “text index required for $text query”

Then upon creating the index again, the same error persists

1 Like