0

I want to update a field in my MongoDB collection as null. Is it possible to do it using Python? The below code is what I tried. I got this exception:

bson.errors.InvalidDocument: documents must have only string keys, key was None

from pymongo import MongoClient
client = MongoClient('localhost:27017')
db = client.data
address = None
db.employee.update({'email':"[email protected]"},{$set:
{'address':address}})

1 Answer 1

1

Python has notion of "None/NULL" to represent null values. But it is not same in MongoDB.

MongoDB doesn't recognize None as NULL value. Hence you should either use null or empty string ""

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.