【发布时间】:2022-01-15 17:17:51
【问题描述】:
我尝试在 Mongodb(版本 4.4.5)中运行以下代码。
db.getCollection('articles').aggregate([
{
$match: {
'art_xml_data.article.journal_id': 'ei',
'art_status': 'publish'
}
},
{
$addFields: {
test: { $replaceAll: { input: '$art_file_path', find: "/", replacement: "_" } }
}
},
{
$project: {
'journal_id': '$art_xml_data.article.article_id',
'file': '$art_file_path',
'year': '$art_xml_data.article.pub_date.preprint.year',
'gn': '$test'
}
}
])
但在执行时显示, 错误:命令失败:{ “好”:0, "errmsg" : "无法识别的表达式'$replaceAll'", “代码”:168, "codeName" : "InvalidPipelineOperator" }
我知道 $replaceOne 和 $replaceAll 聚合是在 Mongo 4.4 版中引入的。这里我的 mongo 版本是 4.4.5 但仍然显示错误。这是版本信息:
MongoDB shell version v4.4.5
Build Info: {
"version": "4.4.5",
"gitVersion": "ff5cb77101b052fa02da43b8538093486cf9b3f7",
"openSSLVersion": "OpenSSL 1.1.1f 31 Mar 2020",
"modules": [],
"allocator": "tcmalloc",
"environment": {
"distmod": "ubuntu2004",
"distarch": "x86_64",
"target_arch": "x86_64"
}
}
【问题讨论】:
-
也许检查服务器输出的内容:db.adminCommand( { getParameter: 1, featureCompatibilityVersion: 1 } )
-
@R2D2 这是输出: { "featureCompatibilityVersion" : { "version" : "4.2" }, "ok" : 1.0 }
-
还有 db.version() ?
-
如果你的服务器是 4.4,你可以通过 db.adminCommand( { setFeatureCompatibilityVersion:
, writeConcern: { wtimeout: 切换到 4.4} } ) -
否则您需要将 4.2 升级到 4.4 ...
标签: mongodb aggregation-framework robo3t