MANOJ MARISWAMY
MANOJ MARISWAMY

Reputation: 43

"Feature not supported: $text" in document db with mongodb 3.6 compatiability

Hi I am using AWS documentDB with mongodb 3.6 compatiability but getting mentioned error in the function below. I am not sure how to get around this.

Index creation

ScenarioSchema.index({
"friendlyId": "text",
"steps.text": "text",
"title": "text"
}, { name: "scenarioTextIndex" });


var createSearchFilter = function (searchOptions)
 {
    var searchTerm = searchOptions.searchText || '';
    if (searchOptions.searchCondition.toUpperCase() === 'AND') {
        searchTerm = searchTerm.split(" ").join('" "');
    }
    if (searchOptions.excludeSearchText) {
        var excludeSearchText = searchOptions.excludeSearchText.split(" ").join(' -');
        searchTerm = searchTerm.concat(" -" + excludeSearchText);
    }
    var allowedPhases = getRoleBasedPhases(searchOptions.userRoles, searchOptions.phases);
    return {$text: {$search: searchTerm}, 'phase.code': {$in: allowedPhases}};
};

I am getting code: 303 errmsg: "Feature not supported: $text" message: "Feature not supported: $text" name: "MongoError"enter code here ok: 0

Upvotes: 2

Views: 5243

Answers (3)

renewabristol
renewabristol

Reputation: 1

future Google-searcher! Amazon wrote this piece about running text search on your DocumentDB instance.

Basically, integrate Elastic Search with DocumentDB.

Upvotes: 0

Marco Sumali
Marco Sumali

Reputation: 59

Amazon DocumentDB is compatible with the MongoDB 3.6 and 4.0 APIs. Unfortunately, there are some features or operators that have not been adopted by Amazon DocumentDB and $text is actually one of them. You can check the list of supported functionality in the following link.

https://docs.aws.amazon.com/documentdb/latest/developerguide/mongo-apis.html

I notice from your code that you want do some search queries on your database. If you're planning to stick to Amazon DocumentDB, you might want to check for $regex to do your search query and you can even combine it with $or operator to do multiple condition for your query.

Some code example:

const searchPhrase = ... // Get the phrase from your search text manipulation
const condition = {
  $or: [
    { friendlyId: { $regex: searchPhrase, $options: "i" } },
    { text: { $regex: searchPhrase, $options: "i" } },
    { title: { $regex: searchPhrase, $options: "i" } },
  ]
};
const searchResults = await ScenarioSchema.find(condition);

Upvotes: 4

D. SM
D. SM

Reputation: 14520

The "MongoDB 3.6 compatibility" means DocumentDB supports some of MongoDB 3.6 features. There are many MongoDB features that DocumentDB does not implement, $text appears to be one of them.

https://www.mongodb.com/atlas-vs-amazon-documentdb

To get around this, use MongoDB.

Upvotes: 3

Related Questions