MongoDB C# ASP.NET Core Create Type Index Discriminator Index

144 views
Skip to first unread message

Kaloyan Manev

unread,
Jun 3, 2018, 5:41:34 PM6/3/18
to mongodb-user

I am using the MongoDB driver for ASP.NET Core 2.0 with C# and I was wondering if I can create an index on the type discriminator filed (that _t field added by mongo itself that hold the class name of the object).

I have data from different types and I want to be able to filter it fasterr based on its type.

Thanks in advance!

Wan Bachtiar

unread,
Sep 3, 2018, 7:37:10 PM9/3/18
to mongodb-user

if I can create an index on the type discriminator filed (that _t field added by mongo itself that hold the class name of the object).

Hi Kaloyan,

It’s been a while since you posted your question, have you found a solution yet ?

The discriminator field is created by the MongoDB .Net/C# driver. You can create the index directly using db.collection.createIndex() via mongo shell. For example:

db.collectionName.createIndex({_t:1})

Regards,
Wan.

Reply all
Reply to author
Forward
0 new messages