Answer the question
In order to leave comments, you need to log in
How to do multiple search and replace in mongodb?
The database has string objects like this: "1.950", "22.451", "1.140"...
These numbers should represent thousands, converting from $toInt gives me "1", "22", "1" and I need " 1950", "22451", "1140".
I would be fine with $replaceOne() if this function changed more than 1 first occurrence.
Can I somehow substitute a regular expression in update() set()? Or maybe there is some other way?
Answer the question
In order to leave comments, you need to log in
Rake-rake-crutches:
string_name: {$toInt: {$arrayElemAt: [{$split: ["$string_to_replace", "."]}, 0]}}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question