MongoEngine / MongoEngine/mongoengine
Unable to insert null into collection
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 4.3k
- Forks
- 1.2k
- Avg merge
- 4h 41m
- Merged PRs (30d)
- 11
Description
I am currently using the DynamicDocument object and have only some pre-defined fields (i.e. user id). The remaining fields are all dynamic. Some of these dynamic fields will be specified with a valid key and a "None" for value. When I try to save the document to MongoDB, the keys with a "None" value are not inserted into the collection. Looking at the BaseDocument to_mongo function, this behavior seems intended.
What is the reasoning behind not inserting null values? I verified that removing the "if value is not None" statement, allows me to insert null into the database.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with mongoengine/base/document.py and the BaseDocument.to_mongo function referenced in the issue; inspect how DynamicDocument fields with None values are handled and look for related tests. Done means the expected persistence behavior for dynamic keys whose values are None is defined and verified against MongoDB serialization.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- mongodb, python
- Domain
- databases
- Issue type
- Feature
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100