简体   繁体   中英

mongoEngine miss the filed when the value is null after save

Here is a sample document:

{"id":1,
"info":{"age":10,"grade":80,"address":"LA"}
}

What I did:

# query the document
student = Student.objects(id=1).first()
# change the info
student.info['address'] = None
# save the change
studen.save()

When I look at the db, this document miss the address field. the info is {"age":10,"grade":80} Why save() operation can auto miss the null field, how to avoid it? (I know use update can keep the null field, but can I use save and still keep the null field?)


You can either try to give it Nan or void string ""

student.info = {"age":10,"grade":80,"address":""}

or

student.info = {"age":10,"grade":80,"address":Nan}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM