How can I use query.fullText()?

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

I added this code on client side and it is also not working.

const datas = await collection.aggregate([{ $match: { $text: { $search: "test" } } }]).toArray();
console.log(datas);

And there’s a record which tokenURIData contains ‘test’, but it returns empty array.

original code

await client.connect()

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

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

const datas = await collection.aggregate([{ $match: { $text: { $search: "queen" } } }]).toArray()

new 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" })

const datas = await collection.aggregate([{ $match: { $text: { $search: "test" } } }]).toArray();
console.log(datas);

seems similar

maybe you can also try this: const datas = await collection.aggregate([{ $match: { $tokenURIData_text: { $search: "test" } } }]).toArray();
I think that you already tried it.

It may be easier to use a regexp

Yeah, I tried and it works the same. :sob: