Let's say I have an abstract class Animal, and subclasses Dog and Cat.
My MongoDB table stores all animals, and uses a the _t type discriminator field in documents.
What I want to do is create a full-text index on 2 properties, one that exists only in Dog documents, and one that exists only in Cat documents. The JSON is straightfoward enough:
{
"dog_only_field" : "text",
"cat_only_field" : "text"
}
But I'd like to do this with the official C# driver. I tried this:
var builder = Builders<Animal>.IndexKeys;
var keys = builder.Text(x => ((Dog)x).MyText).Text(x => ((Cat)x).MyText);
col.Indexes.CreateOne(keys);
But got Unable to determine the serialization information for x => Convert(x).Message.
Cat,DogandAnimalclasses look like? Please post bare minimum testable code.Animalonly has aGuidIdproperty,Doghas astringpropertyDogTextandCathas astringpropertyCatText.