TurnerSoftware / MongoFramework

An "Entity Framework"-like interface for MongoDB
MIT License
392 stars 35 forks source link

Ignore unknown field option #340

Closed azhe403 closed 1 year ago

azhe403 commented 1 year ago

When found an unknown field, is there option for ignore field and return default value of field depend on field type?

image

Turnerj commented 1 year ago

Hey @azhe403 , you can ignore extra elements with an attribute on the model you want to ignore them on.

See the docs here: https://github.com/TurnerSoftware/MongoFramework/blob/main/README.md#Extra-Elements

I'm not sure what you mean about a default values though. By ignoring an element, there would be no property to put a default value on.

azhe403 commented 1 year ago

Hi @Turnerj

In my case is a renaming column from CendolsCount to CendolCount, so old data still with previous field, but changed column will be applied to new data.

I think it not by adding attribute, but leave old data with old field and return default value (e.g. null, zero or false) when query them.

Turnerj commented 1 year ago

OK so this could be a bit of a complicated scenario.

The only other option is performing some sort of migration but you'll be on your own for that. I do have plans to do some sort of migration system for MongoFramework but that would be a long time out.

azhe403 commented 1 year ago

Seem that all can be solved with ExtraElements, i has tried and worked like as expected.

thanks for making this lib great!

I'll close this issue.