Ashok Kumar
Ashok Kumar

Reputation: 403

How to update a field null in mongoDb with python

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

Answers (1)

Nishu Tayal
Nishu Tayal

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

Related Questions