[CSHARP-2350] Collation.FromBsonDocument barfs on some collations Created: 05/Aug/18  Updated: 31/Mar/22

Status: Backlog
Project: C# Driver
Component/s: API
Affects Version/s: 2.7.0
Fix Version/s: None

Type: Improvement Priority: Major - P3
Reporter: Adam Milazzo Assignee: Unassigned
Resolution: Unresolved Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

All



 Description   

Some collation objects returned from the MongoDB server include a version field, but Collation.FromBsonDocument throws an exception if there are any unrecognized fields, and it does not recognize the version field.



 Comments   
Comment by Adam Milazzo [ 27/Nov/18 ]

E.g.

db.createCollection('col',{collation:{locale:'en'}});
db.runCommand("listCollections");

(or do the same via the C# SDK)

The response contains:

"collation" :

{                         "locale" : "en",                         "caseLevel" : false,                         "caseFirst" : "off",                         "strength" : 3,                         "numericOrdering" : false,                         "alternate" : "non-ignorable",                         "maxVariable" : "punct",                         "normalization" : false,                         "backwards" : false,                         "version" : "57.1"                     }

which can't be parsed by Collation.FromBsonDocument.

Comment by Adam Milazzo [ 20/Nov/18 ]

Collation documents are returned from the server as part of the listCollections, listIndexes, etc. commands.

When I said the collation document came from a collection, I was referring to the output of the listCollections command (IIRC) relating to a collection that had previously been created with a collation, not a document inserted into the collection.

It seems to make sense that Collation.FromBsonDocument should be able to parse a collation object returned from the server.

If you still need a code sample, I will write one.

Comment by Ian Whalen (Inactive) [ 19/Nov/18 ]

admilazz can you let us know where you're getting this collation document from? collation docs aren't typically something we put into a collection, it's usually a part of collection or index metadata.

It would also be really useful if you could provide sample code to reproduce.

Comment by Adam Milazzo [ 05/Aug/18 ]

For example, I received this collation document from a collection on MongoDB 3.6.2:

{ "locale" : "en", "caseLevel" : false, "caseFirst" : "off", "strength" : 3, "numericOrdering" : true, "alternate" : "non-ignorable", "maxVariable" : "punct", "normalization" : false, "backwards" : false, "version" : "57.1" }
Generated at Wed Feb 07 21:42:19 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.