Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I change the Type discriminator property in MongoDB?

I am having trouble moving between mongodb and json.net due to polymorphic types. the c# mongodb driver users _t as the discriminator property name and json.net uses $type. I know json.net has this value hardcoded from other research. My question is if anyone knows of a way to rename "_t" to "$type" using the c# mongodb driver?

like image 935
Mike Avatar asked Jul 08 '13 21:07

Mike


1 Answers

I believe you can can create a custom discriminator convention and you can add it to each type you wish to modify;

http://mongodb.github.io/mongo-csharp-driver/2.2/reference/bson/mapping/polymorphism/

Here's an example of a custom discriminator convention which might help you;

http://pastebin.com/9UweEKBe

like image 99
cirrus Avatar answered Oct 16 '22 19:10

cirrus