mongodbaggregation-frameworkrobo3t

MongoError: "Unrecognized expression '$replaceAll'"


I tried to run the following code in Mongodb (Version 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'
        }
    }
])

But on executing it is showing, Error: command failed: { "ok" : 0, "errmsg" : "Unrecognized expression '$replaceAll'", "code" : 168, "codeName" : "InvalidPipelineOperator" }

I know $replaceOne and $replaceAll aggregation is introduced in Mongo version 4.4. Here my mongo version is 4.4.5 but still showing the error. Here is the version info:

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

Solution

  •    db.adminCommand( { setFeatureCompatibilityVersion: "4.4", writeConcern: { wtimeout: 5000 } } )
    

    must solve the problem if your binary is 4.4