Reputation: 403
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}})
Upvotes: 0
Views: 3057
Reputation: 20880
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 ""
Upvotes: 1