[CSHARP-2110] Discriminator of the query of sub typed collections is incorrect Created: 23/Nov/17  Updated: 15/Nov/21  Resolved: 25/Jun/20

Status: Closed
Project: C# Driver
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: T Cools Assignee: Wan Bachtiar
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Description   

I have following scenario:

I'm using the the Mongo C# Driver with CosmosDB and I use a single collection to store different document types. I not really happy with this, but it seems recommended by Microsoft.

I get the collection:

_collection = database.GetCollection<object>("shared").OfType<T>();

When I insert a document the document the configured discriminator is used

Works:
_collection.InsertOne(document);
_collection.Find(filter).SingleOrDefault();

But when I try to query the collection the discriminator is always "FullTypeName, Assemby".

Doesn't work:
_collection.AsQueryable().ToList()

So the configured discriminator value is never used.

Currently it works by setting to discriminator to the value used by the query.

//does not support nested types
classMapInitializer.SetDiscriminator(typeof(T).FullName + ", " + typeof(T).Assembly.GetName().Name);

But we like to give a more functional names to the discriminator which don't break if we refactor.

I had a quick look and it seems that the filter of the OfTypeMongoCollection is not passed to the MongoQueryableImpl. And to can probably solved using a default expression that filters on the configured discriminator type.

Is this something that need to be supported by the library?

Any feedback is appriciated!

Tim



 Comments   
Comment by Rachelle Palmer [ 25/Jun/20 ]

Hi there, thank you for reaching out to MongoDB. As this sounds more like a support issue, I wanted to give you some resources to get this question answered more quickly:

  • our MongoDB support portal, located at support.mongodb.com
  • our MongoDB community forums, located here
  • If you are an Atlas customer, there is free support offered 24/7 in the lower right hand corner of the UI.

Thank you!
Rachelle

Comment by James Turner [ 15/May/19 ]

This sounds very much like CSHARP-1907 with discriminators not being handled consistently.

 

Generated at Wed Feb 07 21:41:38 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.