2,753 questions
Best practices
0
votes
3
replies
30
views
How to prevent DuplicateKeyException when using MongoDB upsert with optimistic concurrency (versioning)?
I'm using MongoDB with the .NET driver and trying to implement an optimistic concurrency pattern with versioning using UpdateOneAsync and IsUpsert = true.
Here is my code:
public Task UpsertAsync(User ...
2
votes
1
answer
88
views
High CPU usage in MongoDB C# Driver due to JIT compilation of BsonMemberMap.GetPropertySetter during projection
I am experiencing a significant CPU spike under high concurrency when executing a simple AsQueryable projection using the MongoDB C# Driver.
After profiling the application and debugging the driver ...
Advice
0
votes
1
replies
59
views
CPU regression in MongoDB for find operations with $in and deep projections
I've encountered a critical performance issue in MongoDB 8.0.15 - 8.0.20. I need your help diagnosing and finding a solution.
After upgrading from version 8.0.14 to any of the versions 8.0.15 - 8.0.20,...
-2
votes
0
answers
121
views
How to fix 'querySrv ECONNREFUSED' error when connecting to MongoDB Atlas from Node.js application?
i was trying to run the project and was getting the below error also tried restricting it to ipv4 like this
Error name: Error
Error code: ECONNREFUSED
Error message: querySrv ECONNREFUSED _mongodb....
0
votes
1
answer
116
views
How can I clone objects without retrieving them in MongoDb?
I use MongoDb in C#. Shown below is an object I want to clone, but also I want to merge it into the same collection.
This is a simplified version of the document I use:
class MyDocument
{
public ...
2
votes
2
answers
97
views
MongoDB .NET - Updating embedded document in list with filters based on Parent and Child
Each Team document contains a list of Player documents. Each Player contains a list of strings named PlayerColors.
The need is to update the PlayerColors of a specific Player within the specific team. ...
2
votes
1
answer
84
views
SocketException after upgrading to C# driver v3.2.0
After upgrading to C# driver v3.2.0 from v3.1.0, we’ve started to receive the following exceptions as UnobservedTaskExceptions in Sentry. SocketException is part of an AggregateException that is ...
2
votes
1
answer
167
views
MongoDB.Bson.BsonSerializationException after C# driver update to 3.5.0
I updated my project MongoDb C# driver to version 3.5.0 (from 3.4.1) and I started receiving this exception:
MongoDB.Bson.BsonSerializationException: 'The discriminator element name cannot be ...
0
votes
0
answers
76
views
Use single IClientSessionHandle instance with multiple tasks executing in parallel
Do not make instance data thread safe by default, it's a thing we know, but do you know, or have you tried, if a single instance of IClientSessionHandle can be used in tasks executing in parallel?
...
1
vote
1
answer
51
views
C# MongoDB.Driver How to find document if grandchild has a value
I hope someone might be able to help.
We have documents in an Atlas MongoDB collection with a structure like this:
{
"Id": "",
"Child1": {
"ChildId": &...
0
votes
1
answer
464
views
MongoDB Driver update issues from version 2.27 to version 3.2.1
I am using Assembly MongoDB.Driver version 2.27 in my C# code (Targeting to netstandard2.1 as need some backward compatibility for older codebase).
When I am changing version of Assembly MongoDB....
1
vote
1
answer
90
views
Error NU1202 MongoDB.Driver update issues
Have a ProjectA created for .NET Standard 2.1 with nuget packages MongoDB.Driver v2.12.0 and AspNetCore.HealthChecks.MongoDb v3.1.3.
As part of MongoDB.Driver package upgrade, it updated the MongoDB....
2
votes
1
answer
74
views
MongoDB - Count number of object in array
I'm trying to perform a single request to find the length of an array in a MongoDB document.
In MongoDB, it can be done with an aggregation but to no success on my own.
db.mycollection.aggregate([{$...
1
vote
1
answer
99
views
MongoDB throws exception when the Modal has Dynamic field
I am trying to migrate my Database from Cosmos to Mongo.
When trying to add an entry for an object which has a C# dynamic Type in MongoDB exception is thrown from the API InsertOneAsync() provided by ...
0
votes
0
answers
123
views
MongoDB C# driver class mapping: map MongoDB nested fields to flat class
I’m trying to do a very simple thing, I want to map a MongoDB document with nested fields to a flat class like so:
Document:
{
code: "123",
data: {
other_code: "456&...