This leads to all grain states using the same mongo collection. It will be the first one that gets created with that key which is likely undeterministic depending on your Orleans application.
A simple test scenario can highlight this bug. You just need 2 grain types with their own states. Depending on which grain type is activated first, will determine which mongo collection is used. I can provide a test repo if need be.
This fix just uses the collection name as the key in the cache.
Currently the statename is used as the key for caching collections in the MongoGrainStorage. However the statename is always set to "state" as seen here in the Orleans source code: https://github.com/dotnet/orleans/blob/2bcd83351385c0dd98cd3a60cdcfb17ce890f966/src/Orleans.Runtime/Core/GrainRuntime.cs#L88C42-L88C42
This leads to all grain states using the same mongo collection. It will be the first one that gets created with that key which is likely undeterministic depending on your Orleans application.
A simple test scenario can highlight this bug. You just need 2 grain types with their own states. Depending on which grain type is activated first, will determine which mongo collection is used. I can provide a test repo if need be.
This fix just uses the collection name as the key in the cache.