How can I use query.fullText()?

Then, is there any method to query datas which certain colume contains substring?

yes, regexp works, and that way of adding an index, you add the index after you connect directly to mongo db from your local computer, you only have to add it once

I tried with regexp method.
I used this code to get the records which contains substring, but this is not working.

$regex: `/${substring}/g`

And I tried to create index on client side to use fullText statement.
But on cloud function side, if I use query.fullText(), it returns an exception and the exception is below.

{"ok":0,"code":27,"codeName":"IndexNotFound","name":"MongoError"}

For first try with regexp, did you try with hardcoded values first instead of variables?

For the second part, you connected to mongodb directly and you created an index?

I tried with hardcoded regexp, but regexp was not working.
And I tried this code to creat index.

const database = client.db("parse")
const collection = database.collection("TblColllection")

await collection.createIndex({ tokenURIData: "text" })

And I used fullText on cloud function like this.

query.fullText('tokenURIData', 'xxx');

Can you list the indexes now?
Was there any error while creating that index?

There was no exception while I was creating index.

Maybe the createIndex function could return some error message

This is my creating index code.

try {
    // Connect the client to the server
    await client.connect();
    // Establish and verify connection
    await client.db('admin').command({ ping: 1 });
    console.log('Connected successfully to server');

    const database = client.db("parse")
    const collection = database.collection("TblColllection")

    await collection.createIndex({ tokenURIData: "text" })

    console.log('Created index successfully');
  } finally {
    // Ensures that the client will close when you finish/error
    await client.close();
  }

Try to list the indexes for that table that are found in the database

It returns this value.

tokenURIData_text

Should I need to use this return value like this?

query.fullText('tokenURIData_text', 'xxx')

How can I list indexes?
Could you tell me how to list indexes?

I listed indexes.

[
  { v: 2, key: { _id: 1 }, name: '_id_' },
  {
    v: 2,
    key: { _fts: 'text', _ftsx: 1 },
    name: 'tokenURIData_text',
    weights: { tokenURIData: 1 },
    default_language: 'english',
    language_override: 'language',
    textIndexVersion: 3
  }
]

Do you still get an error?

Yeah, it still occurs exception.

{"ok":0,"code":27,"codeName":"IndexNotFound","name":"MongoError"}

Did you try the exact syntax used here for the query?

This is my creating index code.

await client.db('admin').command({ ping: 1 });
console.log('Connected successfully to server');

const database = client.db("parse")
const collection = database.collection("TblColllection")

const res = await collection.createIndex({ tokenURIData: "text" })

So after this code, I listed the indexes and result is like below.

[
  { v: 2, key: { _id: 1 }, name: '_id_' },
  {
    v: 2,
    key: { _fts: 'text', _ftsx: 1 },
    name: 'tokenURIData_text',
    weights: { tokenURIData: 1 },
    default_language: 'english',
    language_override: 'language',
    textIndexVersion: 3
  }
]

And I used query.fullText method on cloud function as below.

query.fullText('tokenURIData', request.params.keyword);

The original code was also doing a query after creating the index

Yeah, right. But the code was on client side.
But I need to implement this feature on cloud functions.

yes, just wanted to know if it works that code in client side that was used there