Can't update immutable enum

I have an entity with simple enum ( LicenseType ) in my .Net Core project. I want to update LicenseType field of my entity, but receiving error:

Also, when i try to unset that field i receive such error:image

When performing such operations on my local db instance everything is okey, but using remote fails. My entity model is:

image

And enum:

image

Hi @Kenny_Wood and welcome in the MongoDB Community :muscle: !

Looks like your collection is sharded in production and not in dev which is why you don’t have the issue in dev. It also looks like “LicenceType” is part of the shard key which is immutable before MongoDB 4.2. Which version are you using?

If you are sure that you want to update this field, maybe you should reconsider your shard key and maybe data model.

If you use MongoDB >= 4.2, then you should use a transaction if you want to make this update successful. More considerations here:

Cheers,
Maxime.

Hi, Thanks for your reply.

My problem was resolved by recreating the collection and importing dump data.

Maybe, collection was created in some custom way

Well, yes. My guess is that is was a sharded collection and now you recreated an un-sharded collection that now resides only in the primary shard of its database.

More documentation about the sharding in MongoDB: https://docs.mongodb.com/manual/sharding/

Cheers,
Maxime.