$text not working in realm mongodb data access

I am trying to use $text search in realm react native client and it returns, code 12, message “$text is not allowed in this context”.
here is the code:
const mongodb = user.mongoClient(‘mongodb-atlas’);
const productCollection = mongodb.db(‘database’).collection(‘products’);
productCollection.find({$text: {$search: search}})

@prakhar_tomar Doesn’t look like $text is supported from the client because you must be a system user to call it, see here - https://docs.mongodb.com/realm/mongodb/crud-and-aggregation-apis/#evaluation-operator-availability

I believe what you could do is call a remote function that has system user access however

Thanks for the reply.
If text is not supported then, what would be the best practice for creating a search bar with realm?

Create a (backend) function that performs the $text search.

I found a solution :-
const mongodb = user.mongoClient(‘mongodb-atlas’);
const collection = mongodb.db('db).collection(‘collection’);
collection.aggregate( [ { $search: { autocomplete: { path: ‘’, query: ‘’, }, }, }, ] )

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