"Feature not supported: $text" 在具有 mongodb 3.6 兼容性的 documentdb 中
"Feature not supported: $text" in document db with mongodb 3.6 compatiability
您好,我正在使用具有 mongodb 3.6 兼容性的 AWS documentDB,但在下面的函数中提到了错误。我不确定如何解决这个问题。
创建索引
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}};
};
我收到代码:303
errmsg:“不支持的功能:$text”
消息:“不支持的功能:$text”
名称:“MongoError”enter code here
好的:0
“MongoDB 3.6 兼容性”表示 DocumentDB 支持 一些 MongoDB 3.6 功能。 DocumentDB 没有实现许多 MongoDB 功能,$text 似乎是其中之一。
https://www.mongodb.com/atlas-vs-amazon-documentdb
要解决这个问题,请使用 MongoDB。
Amazon DocumentDB 与 MongoDB 3.6 和 4.0 API 兼容。遗憾的是,有些功能或运算符尚未被 Amazon DocumentDB 采用,$text 实际上就是其中之一。您可以在以下 link.
中查看支持的功能列表
https://docs.aws.amazon.com/documentdb/latest/developerguide/mongo-apis.html
我从你的代码中注意到你想在你的数据库上做一些搜索查询。如果您打算坚持使用 Amazon DocumentDB,您可能需要检查 $regex to do your search query and you can even combine it with $or 运算符来为您的查询执行多个条件。
一些代码示例:
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);
您好,我正在使用具有 mongodb 3.6 兼容性的 AWS documentDB,但在下面的函数中提到了错误。我不确定如何解决这个问题。
创建索引
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}};
};
我收到代码:303
errmsg:“不支持的功能:$text”
消息:“不支持的功能:$text”
名称:“MongoError”enter code here
好的:0
“MongoDB 3.6 兼容性”表示 DocumentDB 支持 一些 MongoDB 3.6 功能。 DocumentDB 没有实现许多 MongoDB 功能,$text 似乎是其中之一。
https://www.mongodb.com/atlas-vs-amazon-documentdb
要解决这个问题,请使用 MongoDB。
Amazon DocumentDB 与 MongoDB 3.6 和 4.0 API 兼容。遗憾的是,有些功能或运算符尚未被 Amazon DocumentDB 采用,$text 实际上就是其中之一。您可以在以下 link.
中查看支持的功能列表https://docs.aws.amazon.com/documentdb/latest/developerguide/mongo-apis.html
我从你的代码中注意到你想在你的数据库上做一些搜索查询。如果您打算坚持使用 Amazon DocumentDB,您可能需要检查 $regex to do your search query and you can even combine it with $or 运算符来为您的查询执行多个条件。
一些代码示例:
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);