Allow exclude_none
, exclude_unset
, exclude_defaults
on engine.save()
#162
Labels
enhancement
New feature or request
Feature request
Context
I need to save ODMantic documents, but almost always I need to save them in a way that unset fields are not persisted in mongoDB. This is mainly because unsetted fields should not be included in unique, sparse indexes. Also I can see how exclude_none and exclude_defaults can be useful.
Solution
I think that
engine.save
should allowexclude_none
,exclude_unset
andexclude_defaults
as keyword arguments in its. public API, just likePydantic.BaseModel.dict
. I would expect that when passing any of this excluding argument, the fields that are none/unset/default value would not be persisted in the DB.Alternative solutions
Currently I am working with this approach:
but I think it's ugly and should be probably handled better in ODMantic right away.
What do you think of this idea? I could perhaps help with a PR with some guidance.
The text was updated successfully, but these errors were encountered: