0
votes

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"
    }
}
Maybe check what the server output from: db.adminCommand( { getParameter: 1, featureCompatibilityVersion: 1 } )R2D2
@R2D2 this is the output: { "featureCompatibilityVersion" : { "version" : "4.2" }, "ok" : 1.0 }Anoop Sankar
Also db.version() ?R2D2
If your server is 4.4 , you can switch to 4.4 via : db.adminCommand( { setFeatureCompatibilityVersion: <version>, writeConcern: { wtimeout: <timeout> } } )R2D2
Otherways you will need to upgrade 4.2 to 4.4 ...R2D2