I am relatively new to MongoDB and using it with the C# Driver.
Context: We are maintaining a list of translations. So each entry has Language, Key, and Value. Each combination of Language and Key should only result in one Value.
I would like to have the Language and Key be case-insensitive.
For my Find methods, I did set the recordFilter to:
record => key.ToUpperInvariant() == record.Key.ToUpperInvariant() && language.ToUpperInvariant() == record.Language.ToUpperInvariant()
and that seems fine.
There is a UI to maintain the translations, which will always have the user edit them by Key. Meaning there will always be like 10 entries of the same Key and different languages incoming, and I don’t know whether they are new or updated, so I have to use Upsert on each.
The first is the outer method, which calls the second method that is supposed to be more generic, i.e. to be used in some other cases.
Now, when I didn’t use the .ToUpperInvariant() calls, this worked as expected - existing values were updated, new entries were added with Key, Language and Value.
After I added .ToUpperInvariant(), existing values are still properly updated, but new entries have only a Key - no Language and Value.
Why is this?
And, more importantly, how can I fix this? Is there any other option to make my filter case insensitive?
I found out that I could use SetOnInsert, but I’m not sure if/how that could be a clean solution.
I’m glad about any hints or pointers