Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

regexReplace/replaceAll is not evaluated in update command #506

Open
mihaimorcov opened this issue Mar 8, 2024 · 0 comments
Open

regexReplace/replaceAll is not evaluated in update command #506

mihaimorcov opened this issue Mar 8, 2024 · 0 comments

Comments

@mihaimorcov
Copy link

mihaimorcov commented Mar 8, 2024

Hey, how can I replace all occurences of a string in a field?
I tried using $replaceAll and $regexReplace and few other commands but the value in the end is an object field with the literal command, not the evaluated regex replace.
Please help.
and FYI the query "$regex" seems to work fine, only the matching doc is updated.
the update section is the issue

script:

{
  "databaseChangeLog": [
    {
      "changeSet": {
        "id": "replace",
        "author": "yourname",
        "changes": [
          {
            "runCommand": {
              "command": {
                "$rawJson": {
                  "findAndModify": "myCollection",
                  "query": {
                    "myField": {
                      "$regex": "thisText"
                    }
                  },
                  "update": {
                    "$set": {
                        "$replaceAll": {
                          "input": "$myField",
                          "find": "thisText",
                          "replacement": "thatText"
                        }
                    }
                  }
                }
              }
            }
          }
        ]
      }
    }
  ]
}

value updated:

"myField": {
                        "$replaceAll": {
                          "input": "$myField",
                          "find": "thisText",
                          "replacement": "thatText"
                        }
@mihaimorcov mihaimorcov changed the title regexReplace is not evaluated in update command regexReplace/replaceAll is not evaluated in update command Mar 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant