question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Ignore null properties by default

See original GitHub issue

Effectively default the behaviour of BsonIgnoreIfNull on all properties. If I understand it correctly, there shouldn’t be any noticeable impact from this change besides less data in the DB.

More research may need to be done and asked about directly to MongoDB themselves.

Pros

  • Less storage used by MongoDB
  • Less data to send down the wire (AFAIK null properties are still sent - may depend on the driver)

Cons

  • If you depend on null being saved (which is definitely possible), it obviously won’t which would break things. At minimum would need a way to opt-out of default ignoring of null values - whether that is MongoFramework-wide or type-wide would still need to be determined.

Notes

  • No known impact for querying performance in the DB because of ignored properties (eg. doesn’t seem to impact indexing)

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:8 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
NO1225commented, Dec 23, 2021

I think making this optional will be more appropriate I have this case which will be impacted with such a decision I have made dynamic content which will be created dynamically using a dynamically created schema The fields may be required and may be nullable In case of nullable fields, I still need the key to be returned when returning the content to the front end so that the schema of a content stay somewhat consistence In case the ignore null by default was enforced, I will have to get also the schema and compare and attach any null field key to the returned object, which may be cumbersome in case of a paginated list of data Thank you

0reactions
Turnerjcommented, Dec 30, 2021

Sorry for the late response, Yes a way to opt out is perfect for my scenario

All good mate! It is the holidays for most of the world, you don’t need to get back to me instantly.

To cover the case completely, i have a dynamic content system, The structure of the Content Item itself is defined in another collection, and the structure will contain the fields of the content item, field options and type, one of the field options is that if the field is required or not, When creating a content item, you have to choose which structure this content item adhere to, and if there is a nullable fields in that structure, these values may be saved as null in the content item,

The problem when these null values are ignore is that when returning this content item, some of the fields will be missing and i can’t ensure the structure of the content item unless i validate with the structure when reading, which will take time and oppose the purpose of saving it as a read ready item

That sounds like a very interesting project. Is this part of an internal project or maybe an open source tool? (This is for my own curiousity as it sounds pretty cool)

OK, I see what you mean here with the structure. That makes sense to me and will update the issue description accordingly noting that it should (at minimum) have an opt-out. You won’t need to worry about this being done in the short term though, this particular issue is more of a backlog item for me.

Note: Let me say that i’m a huge fan of this library and using it saved me a lot of time and effort, A big thank you isn’t enough

Thanks!

They say you miss 100% of shots you don’t take so… if it is really beneficial to you and you (or the company you work for/with/that is using it etc) could financially contribute, that would be pretty awesome. I do offer support plans which can be helpful for businesses or even just a little something via GitHub Sponsors can go a long way.

If you can’t do that, spreading the word about MongoFramework (and/or any of my other projects) can also be helpful for the long term sustainability of my OSS projects.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Ignore Null Fields with Jackson
This quick tutorial is going to cover how to set up Jackson to ignore null fields when serializing a java class.
Read more >
How to tell Jackson to ignore a field during serialization if ...
To omit all null values in the class as a default, annotate the class. Per-field/getter annotations can still be used to override this ......
Read more >
3 ways to ignore null fields while converting Java object ...
You can ignore null fields at the class level by using @JsonInclude(Include.NON_NULL) to only include non-null fields, thus excluding any attribute whose value...
Read more >
How to ignore properties with System.Text.Json
Learn how to ignore properties when serializing with System.Text. ... Ignore all null-value properties; Ignore all default-value properties ...
Read more >
JsonSerializerOptions.IgnoreNullValues Property
Gets or sets a value that indicates whether null values are ignored during serialization and deserialization. The default value is false.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found