0

I'm trying to figure a quick way to replace blank strings ('') that I have in a lot of my documents (across many fields) with MongoDB's null value.

In MongoDB docs, I was hoping to use ReplaceAll, but I can't figure out how to execute the same thing in pymongo unless I do replace_one().

Is there an efficient way to do this?

1
  • 1
    You can use the Collection's update_many method for this purpose. I guess you need to specify all the fields that requires the update - both in the query filter and the update. Commented Jul 8, 2022 at 5:15

1 Answer 1

1

Currently pymongo does not support replace all. Most effective way to update many documents would be update_many. It looks something like this:

db.my_db.update_many(
    filter={'field_1': ""},
    update={'$set': {'field_1': None}}
)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.