ReplaceOne operator is not supported for mongo db

Replace character in string during projecting the data.
I am getting this error for replaceOne operator, which works perfectly directly on mongo, but it's making an issue when I try to use it through metabase

$replaceOne' on server mongo-westus.XXX.xxx.azure.com:10222. The full response is { "ok" : 0.0, "errmsg" : "unknown operator: $replaceOne", "code" : 168, "codeName" : "168"

This error shows when I try to use replaceOne operator on projection section

"hashtag": { $replaceOne: { input: "$hashtag", find: "#", replacement: "%23" } },

Can u please advice

Hi @alaahammouda
Which version of Mongo are you using? Seems like there has been a lot of changes to that operator, but it's working as expected, when I test with Mongo 5.0
[{"$project":{"_id":"$_id","vendor":"$vendor","category":{"$replaceOne":{input:"$category",find:"G",replacement:"REPLACE"}},"ean":"$ean","title":"$title","id":"$id","price":"$price","created_at":"$created_at","rating":"$rating"}},{"$limit":1048575}]

1 Like

I use ltrim here and it fix my issue without the hassle of upgrading mongo
https://docs.mongodb.com/manual/reference/operator/aggregation/ltrim/

1 Like