How to ignore the property on insert and not on serialization?

In have a situation like to ignore a property when saving a model in MongoDB, but not ignoring it when serializing to JSON.

Let me know is there any way to achieve using .net driver.

Hi @

I suggest you create a method whithin the relevant classes to form the end document you going to pass to to the insert command.

Eg. getStoreDoc

This way this method can include only relevant fields or maybe even have a decision logic


Actually we are sharing the common properties in both domain and data model.

So design can’t be change.

I don’t understand what this has to do with adding an additional method?

There is no feature in MongoDB to automatically ignore fields in an inserted doc. Maybe if you use an ODM library on the application side it might have some annotations for it but I am not familiar with that…