[CSHARP-2066] Positional operator not working when running inside Docker container Created: 15/Oct/17  Updated: 28/Oct/23  Resolved: 19/Apr/19

Status: Closed
Project: C# Driver
Component/s: Read Operations
Affects Version/s: 2.4.4
Fix Version/s: 2.9.0

Type: Bug Priority: Major - P3
Reporter: John Knoop Assignee: Dmitry Lukyanov (Inactive)
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Attachments: PNG File mongodb.png    
Issue Links:
Related

 Description   

This code works great when I run it in a standard .NET Core console app:

collection.UpdateOne(
    filter: Builders<Animal>.Filter.Where(x => x.Subdocument.Subarray.Any(itm => itm.SomeProperty == "foobar")),
    update: Builders<Animal>.Update.Inc(x => x.Subdocument.Subarray[-1].SomeNumericProperty, 10)
);

But when I run that same console app in a Linux container on my Windows machine, I get this exception:

MongoBulkWriteException`1: A bulk write operation resulted in one or more errors.
cannot use the part (Subarray of Subdocument.Subarray.−1.SomeNumericProperty) to traverse the element ({Subarray: [ /* All elements of Subarray listed here */ ]})
MongoDB.Driver.MongoCollectionImpl+<BulkWriteAsync>d__22.MoveNext()
 
MongoWriteException: A write operation resulted in an error.
cannot use the part (Subarray of Order.Subarray.−1.SomeNumericProperty) to traverse the element ({Items: [ /* All elements of Subarray listed here */ ]})

I've tried with simpler update expressions, like just set a property without any positional operator, and that works, so my conclusion is that it has something to do with the positional operator.



 Comments   
Comment by Githook User [ 19/Apr/19 ]

Author:

{'name': 'Unknown', 'username': 'johnknoop', 'email': 'knoopjohn@gmail.com'}

Message: CSHARP-2066: Positional operator should work regardless of the region settings.
Branch: master
https://github.com/mongodb/mongo-csharp-driver/commit/4213e0505c60f8922e616b3941a55bac23101b5c

Comment by John Knoop [ 03/Dec/18 ]

For anyone else who feel they can't wait forever on this, here's a workaround: Set NumberFormat to NumberFormatInfo.InvariantInfo on the CultureInfo of the current thread, and it works as expected.

Comment by John Knoop [ 19/Nov/18 ]

I've created a project that let's you reproduce the bug. Just follow the instructions in the readme: https://github.com/johnknoop/mongodb2066

Comment by Vincent Kam (Inactive) [ 08/Oct/18 ]

https://github.com/mongodb/mongo-csharp-driver/pull/345

Comment by John Knoop [ 29/Sep/18 ]

For more information, there was a discussion on Google Groups that led up to this:

https://groups.google.com/forum/?utm_medium=email&utm_source=footer#!msg/mongodb-user/gNTRS3zdg0w/l3XycZuhBAAJ

Comment by John Knoop [ 26/Sep/18 ]

Since it's been a year and this ticket hasn't gotten any attention, I decided to clone your repo and do some investigation myself.

It turns out, when I use ASP.NET Core request localization in my web app, I get the exception above. But when I disable request localization, everything works. That led me to suspect that there is a string formatting going on somewhere that doesn't use the invariant culture.

Once I attached your source code to my project, I was able to observe the behaviour in detail (see image).

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