[System] You are an assistant of MongoDB Community who is responsible for answering the questions related with MongoDB.

[System] The following conversation has title: Bug in c# Driver 2.11.0 and tags: ['dot-net']

[User]
Text:After many hours trying to figure out the issue i have found that the C# Drivers 2.11.0 have an issue. Depending on what other third party libraries have been used before using the driver they will just throw timeouts exception. Reverting the Driver to 2.10.4 fix the issue. So it’s something that have been added between both version. Right now i have found that if you open a MongoClient at the begining of the application (first line in the program.cs) it will work even after calling the third party dll’s that cause mongo to fail. If instead you call any of these third party dll then try to make any call to mongo you will always have timeout error. I have more details on the operation i was doing over at stackoverflow https://stackoverflow.com/q/63305491/2748412
Code:

[User]
Text:Is there anyways to use allowDiskUse on a find with version 2.10.4
Code:

[Assistant]
Text:Hi @CyberFranck_N_A and welcome to the forums,Is there anyways to use allowDiskUse on a find with version 2.10.4The allowDiskUse option is specific for MongoDB Aggregation framework only. The option enables writing to temporary files. When set to  true  it allows aggregation stages to write data to the  _tmp  subdirectory in the  dbPath  directory.This is not related to a specific MongoDB driver or version, this is the behaviour of the server.Looking at the error stack trace that you posted on StackOverflow:A timeout occured after 30000ms selecting a server using CompositeServerSelector{ Selectors = MongoDB.Driver.MongoClient+AreSessionsSupportedServerSelector, LatencyLimitingServerSelector{ AllowedLatencyRange = 00:00:00.0150000 } }. Client view of cluster state is { ClusterId : “1”, ConnectionMode : “Automatic”, Type : “Unknown”, State : “Disconnected”, Servers : [{ ServerId: “{ ClusterId : 1, EndPoint : “127.0.0.1:27017” }”, EndPoint: “127.0.0.1:27017”, ReasonChanged: “ServerInitialDescription”, State: “Disconnected”, ServerVersion: , TopologyVersion: , Type: “Unknown”, LastHeartbeatTimestamp: null, LastUpdateTimestamp: “2020-08-07T16:00:54.4780565Z” }] }.Also from the server log:{“t”:{“$date”:“2020-08-07T12:31:05.334-04:00”},“s”:“I”,  “c”:“-”,        “id”:20883,   “ctx”:“conn249”,“msg”:“Interrupted operation as its client disconnected”,“attr”:{“opId”:4183920}}
{“t”:{“$date”:“2020-08-07T12:31:05.334-04:00”},“s”:“I”,  “c”:“NETWORK”,  “id”:22989,   “ctx”:“conn249”,“msg”:“Error sending response to client. Ending connection from remote”,“attr”:{“error”:{“code”:6,“codeName”:“HostUnreachable”,“errmsg”:“Connection reset by peer”},“remote”:“127.0.0.1:61403”,“connectionId”:249}}From a brief look, it is likely that the client was disconnected from the server. Is there something on the network layer that is interrupting the connection ?If you’re still encountering this issue, and able to reproduce it consistently, could you please provide:Regards,
Wan.
Code:allowDiskUsetrue_tmpdbPath

[User]
Text:Error is reproducible 100% of the time.Switching driver from 2.11.0 to 2.10.4 fix the issue.MongoDB server version 4.4.0
Windows 10 latest version (brand new pc new install)example code based on the stack overflow old code that does work :here the similar example but this does not workNoticed the ONLY difference is that i called another third party dll before yours and it doesn’t work with 2.11.0 but if i switch to 2.10.4 both code works. I do use over 250 third party DLL and only a single one cause that issue if i instantiate it before yours. I have contacted their support and as their dll do not crash and they say it’s up to you to fix your issue. I assumed there must be culture info issue between same dll or something like it that is not standard in your code in 2.11.0 that is correct in 2.10.4
Code: // get the client
 var client = new MongoClient("ConnectionStringHere");

// get the database
var db = client.GetDatabase("SomeDatabase");

// create the filter for collection names
var filter = new BsonDocument("name", "SomeCollection");
var options = new ListCollectionNamesOptions { Filter = filter };

// check if the filter return at least 1 record
var containAtLEastOneRecord = db.ListCollectionNames(options).Any();

// declare a third party DLL object
var test = ThirdPartyDll.SomeClass();
// declare a third party DLL object
var test = ThirdPartyDll.SomeClass();

 // get the client
 var client = new MongoClient("ConnectionStringHere");

// get the database
var db = client.GetDatabase("SomeDatabase");

// create the filter for collection names
var filter = new BsonDocument("name", "SomeCollection");
var options = new ListCollectionNamesOptions { Filter = filter };

// check if the filter return at least 1 record
var containAtLEastOneRecord = db.ListCollectionNames(options).Any();

[Assistant]
Text:Hi @CyberFranck_N_A,Thanks for the extra information. Would you be able to share the name of this third party DLL ? Essentially an attempt to create a reproducible test case for others.Also, do you get any warning or error message during build time ?Regards,
Wan
Code:

[User]
Text:The third party DLL is called Eyeshot. It’s a proprietary CAD engine. There is no error or warning regarding this at build time in the list. The only one i get is the runtime exceptionA timeout occured after 30000ms selecting a server using CompositeServerSelector…
Code:

[Assistant]
Text:Hi @CyberFranck_N_A,The third party DLL is called Eyeshot. It’s a proprietary CAD engine.Thanks for that information. Unfortunately it’s challenging to debug an issue without a reproducible test case.Could you try setting up MongoDB on a different machine, and connecting to it remotely ? You could try to spin up your own LAN server, or just spin-up free-shared-tier MongoDB Atlas. Just guessing, but I would like to know whether your machine is overloaded on runtime which prevents the local server to responds adequately.Regards,
Wan.
Code:

[User]
Text:the DB is not local. I have ordered a brand new PC with windows 10 installed and Mongo community on it and that’s the only thing installed. After test are complete we will create a dedicated VM running on Windows Server. My test are done from my PC connecting to that remote computer. Also i do have the same issue while trying to connect to my local database too. The server is running a Ryzen 9 3950X 16 cores and local i am running the threadripper 3970X 32 cores so being overloaded i don’t think that’s the problem here.
Code:

[Assistant]
Text:Hi,
I’m spreadly facing the same issue connecting to Atlas on DEV and STAGING environment, i.e. different clients, different Atlas clusters. Cannot say it’s because of a specific 3rd party dll, I’m still investigating.
I’ll try to downgrade the driver to the 2.10.4 on the DEV one and try to reproduce.
For both of my envs I’ve a WebAPI app on Azure Germany which connects to Atlas cluster, both as M0 Sandbox (General) deployed on AWS / Frankfurt (eu-central-1).
PROD is still running with the 2.10.2 with no problems. Also, the code is not changed around the driver usage.
Code:

[User]
Text:So i might not be just due to the DLL loading order even if i can actually reproduce this every single time by changing the order only ?
Code:

[Assistant]
Text:Today I downgraded the DEV and the STAGING environments to 2.10.4 and later I was debugging a branched codebase running the driver version 2.11.0 getting the timeout too.
I downgraded the driver in the branched as well to 2.10.4 and I’m not facing the issue anymore.
Unfortunately I have no so much time to investigate into this deeper, but I’m 100% sure the code around the driver wasn’t changed and the only difference is the driver version. I’ll wait the next version to check if the issue is solved.
Code:

[Assistant]
Text:I have the same problem with just a simple WinForms application trying to enumerate DB’s on the local server.
The problem was intermittent and was solved when I downgraded to driver version 2.10.4.
The only thing I did on the server is define an admin user with password protection on the DB.
Code:

[Assistant]
Text:Hi @Oren_Lev, and welcome to the forum,Although you may see a similar error message, the cause may be entirely different. For example, both a third party DLL interference versus network interference could cause a CompositeServerSelector issue (amongst other things).I have the same problem with just a simple WinForms application trying to enumerate DB’s on the local server.If the issue that you are encountering is reproducible, please open a new discussion thread/topic. Please provide:Best regards,
Wan.
Code:

[Assistant]
Text:We are using 2.11.5 and we got this issue as well. It doesn’t happen very often.A timeout occured after 30000ms selecting a server using CompositeServerSelector{ Selectors = MongoDB.Driver.MongoClient+AreSessionsSupportedServerSelector, LatencyLimitingServerSelector{ AllowedLatencyRange = 00:00:00.0150000 } }. Client view of cluster state is { ClusterId : “1”, ConnectionMode : “Automatic”, Type : “Sharded”, State : “Disconnected”, Servers : [{ ServerId: “{ ClusterId : 1, EndPoint : “192.168.225.110:27017” }”, EndPoint: “192.168.225.110:27017”, ReasonChanged: “InvalidatedBecause:ChannelException:MongoDB.Driver.MongoConnectionException: An exception occurred while receiving a message from the server. —> System.IO.IOException: Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host. —> System.Net.Sockets.SocketException: An existing connection was forcibly closed by the remote host
at System.Net.Sockets.Socket.EndReceive(IAsyncResult asyncResult)
at System.Net.Sockets.NetworkStream.EndRead(IAsyncResult asyncResult)
.
.
.
— End of stack trace from previous location where exception was thrown —
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at MongoDB.Driver.Core.Servers.Server.ServerChannel.d__33`1.MoveNext()”, State: “Disconnected”, ServerVersion: , TopologyVersion: , Type: “Unknown”, LastHeartbeatTimestamp: null, LastUpdateTimestamp: “2021-01-20T16:05:37.3963307Z” }] }.
Code:

[Assistant]
Text:Hi, Sam,Thank you for reaching out to us about this issue. Without the full stack trace, it is difficult to diagnose the issue definitively. We did however recently discover and fix a race condition in our SDAM implementation, CSHARP-3302. A fix for CSHARP-3302 has been released in .NET/C# Driver 2.11.6. Please try upgrading and letting us know if this resolves your sporadic server selection timeout issues.Thanks,
James
Code:

[Assistant]
Text:Hi,
I have the same issue here even after using the 2.11.6 driver.
The connection string am using to create the Mongo Client is the following:and the stack trace of the error is the following:if you need any help to reproduce the issue please let me know.
Any help is appreciated.
Code:   var database = new MongoClient("mongodb+srv://#userName:#password@cluster0.eqam6.gcp.mongodb.net/database_name?retryWrites=true&w=majority&connect=replicaSet");
[MESSAGE] --- A timeout occured after 30000ms selecting a server using CompositeServerSelector{ Selectors = MongoDB.Driver.MongoClient+AreSessionsSupportedServerSelector, LatencyLimitingServerSelector{ AllowedLatencyRange = 00:00:00.0150000 } }. Client view of cluster state is { ClusterId : "1", ConnectionMode : "ReplicaSet", Type : "ReplicaSet", State : "Disconnected", Servers : [{ ServerId: "{ ClusterId : 1, EndPoint : "Unspecified/cluster0-shard-00-00.eqam6.gcp.mongodb.net:27017" }", EndPoint: "Unspecified/cluster0-shard-00-00.eqam6.gcp.mongodb.net:27017", ReasonChanged: "Heartbeat", State: "Disconnected", ServerVersion: , TopologyVersion: , Type: "Unknown", HeartbeatException: "MongoDB.Driver.MongoConnectionException: An exception occurred while opening a connection to the server. ---> System.TimeoutException: Timed out connecting to Unspecified/cluster0-shard-00-00.eqam6.gcp.mongodb.net:27017. Timeout was 00:00:30.
   at MongoDB.Driver.Core.Connections.TcpStreamFactory.<ConnectAsync>d__7.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at MongoDB.Driver.Core.Connections.TcpStreamFactory.<CreateStreamAsync>d__4.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at MongoDB.Driver.Core.Connections.SslStreamFactory.<CreateStreamAsync>d__4.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at MongoDB.Driver.Core.Connections.BinaryConnection.<OpenHelperAsync>d__51.MoveNext()
   --- End of inner exception stack trace ---
   at MongoDB.Driver.Core.Connections.BinaryConnection.<OpenHelperAsync>d__51.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at MongoDB.Driver.Core.Servers.ServerMonitor.<InitializeConnectionAsync>d__32.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)
   at MongoDB.Driver.Core.Servers.ServerMonitor.<HeartbeatAsync>d__34.MoveNext()", LastHeartbeatTimestamp: "2021-02-23T09:14:35.3589542Z", LastUpdateTimestamp: "2021-02-23T09:14:35.3589542Z" }, { ServerId: "{ ClusterId : 1, EndPoint : "Unspecified/cluster0-shard-00-01.eqam6.gcp.mongodb.net:27017" }", EndPoint: "Unspecified/cluster0-shard-00-01.eqam6.gcp.mongodb.net:27017", ReasonChanged: "Heartbeat", State: "Disconnected", ServerVersion: , TopologyVersion: , Type: "Unknown", HeartbeatException: "MongoDB.Driver.MongoConnectionException: An exception occurred while opening a connection to the server. ---> System.TimeoutException: Timed out connecting to Unspecified/cluster0-shard-00-01.eqam6.gcp.mongodb.net:27017. Timeout was 00:00:30.
   at MongoDB.Driver.Core.Connections.TcpStreamFactory.<ConnectAsync>d__7.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at MongoDB.Driver.Core.Connections.TcpStreamFactory.<CreateStreamAsync>d__4.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at MongoDB.Driver.Core.Connections.SslStreamFactory.<CreateStreamAsync>d__4.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at MongoDB.Driver.Core.Connections.BinaryConnection.<OpenHelperAsync>d__51.MoveNext()
   --- End of inner exception stack trace ---
   at MongoDB.Driver.Core.Connections.BinaryConnection.<OpenHelperAsync>d__51.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at MongoDB.Driver.Core.Servers.ServerMonitor.<InitializeConnectionAsync>d__32.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)
   at MongoDB.Driver.Core.Servers.ServerMonitor.<HeartbeatAsync>d__34.MoveNext()", LastHeartbeatTimestamp: "2021-02-23T09:14:35.4419744Z", LastUpdateTimestamp: "2021-02-23T09:14:35.4419744Z" }, { ServerId: "{ ClusterId : 1, EndPoint : "Unspecified/cluster0-shard-00-02.eqam6.gcp.mongodb.net:27017" }", EndPoint: "Unspecified/cluster0-shard-00-02.eqam6.gcp.mongodb.net:27017", ReasonChanged: "Heartbeat", State: "Disconnected", ServerVersion: , TopologyVersion: , Type: "Unknown", HeartbeatException: "MongoDB.Driver.MongoConnectionException: An exception occurred while opening a connection to the server. ---> System.TimeoutException: Timed out connecting to Unspecified/cluster0-shard-00-02.eqam6.gcp.mongodb.net:27017. Timeout was 00:00:30.
   at MongoDB.Driver.Core.Connections.TcpStreamFactory.<ConnectAsync>d__7.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at MongoDB.Driver.Core.Connections.TcpStreamFactory.<CreateStreamAsync>d__4.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at MongoDB.Driver.Core.Connections.SslStreamFactory.<CreateStreamAsync>d__4.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at MongoDB.Driver.Core.Connections.BinaryConnection.<OpenHelperAsync>d__51.MoveNext()
   --- End of inner exception stack trace ---
   at MongoDB.Driver.Core.Connections.BinaryConnection.<OpenHelperAsync>d__51.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at MongoDB.Driver.Core.Servers.ServerMonitor.<InitializeConnectionAsync>d__32.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)
   at MongoDB.Driver.Core.Servers.ServerMonitor.<HeartbeatAsync>d__34.MoveNext()", LastHeartbeatTimestamp: "2021-02-23T09:14:35.3579464Z", LastUpdateTimestamp: "2021-02-23T09:14:35.3579464Z" }] }.

[Assistant]
Text:CSHARP-3302I’ve been watching this thread for a couple months as we are experiencing the same issue.   We are running three instances of mongo, each in an EC2 instance inside the same VPC and subnet, configured as a replica set.  We have been receiving the same CompositeServerSelector error in a few different flavors, and upgrading to the 2.11.6 CSHARP driver version did not improve these timeouts.We were hit a rash of these in production last week and applied a minPoolSize=20 to the most active mongoDB API clients, and that seems to have improved it slightly, but not eliminated the problem.  This newer connection string is: mongodb://username:password@mongo0:27017,mongo1:27017,mongo2:27017/admin?authSource=admin&replicaSet=rs0&minPoolSize=20&maxPoolSize=500The stack trace of the errors we are seeing:We are not experiencing primary stepdowns, but may be seeing widely varying load conditions that are affecting the RTT.From the primary:As far I can tell with multiple dev reviews, we are correctly using the singleton instantiation of the MongoClient and rely on it to manage the connection pools when needed.When the mongo pool hangs, the API response times spike, then monotonically decrease until the API container that is using the MongoClient is recycled because of connection timeouts.Screenshot 2021-03-15 1609061605×505 65.6 KBMy next thought is to start playing with localThreshold to increase the window above the default 15ms to make sure that one or more servers are available in extreme events.  Is there a way to get the RTT to servers as seen from the mongo driver and dump those in the case of these timeouts to see if they are limiting?
Code:CompositeServerSelectorminPoolSize=20mongodb://username:password@mongo0:27017,mongo1:27017,mongo2:27017/admin?authSource=admin&replicaSet=rs0&minPoolSize=20&maxPoolSize=500[22:19:41 ERR] A timeout occured after 30000ms selecting a server using CompositeServerSelector{ Selectors = MongoDB.Driver.MongoClient+AreSessionsSupportedServerSelector, LatencyLimitingServerSelector{ AllowedLatencyRange = 00:00:00.0150000 } }. Client view of cluster state is { ClusterId : "1", ConnectionMode : "ReplicaSet", Type : "ReplicaSet", State : "Disconnected", Servers : [{ ServerId: "{ ClusterId : 1, EndPoint : "Unspecified/mongo0:27017" }", EndPoint: "Unspecified/mongo0:27017", ReasonChanged: "Heartbeat", State: "Disconnected", ServerVersion: , TopologyVersion: , Type: "Unknown", HeartbeatException: "MongoDB.Driver.MongoConnectionException: An exception occurred while receiving a message from the server.
 ---> System.TimeoutException: The operation has timed out.
   at MongoDB.Driver.Core.Misc.StreamExtensionMethods.ReadAsync(Stream stream, Byte[] buffer, Int32 offset, Int32 count, TimeSpan timeout, CancellationToken cancellationToken)
   at MongoDB.Driver.Core.Misc.StreamExtensionMethods.ReadBytesAsync(Stream stream, Byte[] buffer, Int32 offset, Int32 count, TimeSpan timeout, CancellationToken cancellationToken)
   at MongoDB.Driver.Core.Connections.BinaryConnection.ReceiveBufferAsync(CancellationToken cancellationToken)
   --- End of inner exception stack trace ---
   at MongoDB.Driver.Core.Connections.BinaryConnection.ReceiveMessageAsync(Int32 responseTo, IMessageEncoderSelector encoderSelector, MessageEncoderSettings messageEncoderSettings, CancellationToken cancellationToken)
   at MongoDB.Driver.Core.WireProtocol.CommandUsingCommandMessageWireProtocol`1.ExecuteAsync(IConnection connection, CancellationToken cancellationToken)
   at MongoDB.Driver.Core.Connections.IsMasterHelper.GetResultAsync(IConnection connection, CommandWireProtocol`1 isMasterProtocol, CancellationToken cancellationToken)
   at MongoDB.Driver.Core.Servers.ServerMonitor.GetIsMasterResultAsync(IConnection connection, CommandWireProtocol`1 isMasterProtocol, CancellationToken cancellationToken)
   at MongoDB.Driver.Core.Servers.ServerMonitor.HeartbeatAsync(CancellationToken cancellationToken)", LastHeartbeatTimestamp: "2021-03-14T22:18:27.4390847Z", LastUpdateTimestamp: "2021-03-14T22:18:27.4390850Z" }, { ServerId: "{ ClusterId : 1, EndPoint : "Unspecified/mongo1:27017" }", EndPoint: "Unspecified/mongo1:27017", ReasonChanged: "Heartbeat", State: "Disconnected", ServerVersion: , TopologyVersion: , Type: "Unknown", HeartbeatException: "MongoDB.Driver.MongoConnectionException: An exception occurred while opening a connection to the server.
 ---> MongoDB.Driver.MongoConnectionException: An exception occurred while receiving a message from the server.
 ---> System.TimeoutException: The operation has timed out.
   at MongoDB.Driver.Core.Misc.StreamExtensionMethods.ReadAsync(Stream stream, Byte[] buffer, Int32 offset, Int32 count, TimeSpan timeout, CancellationToken cancellationToken)
   at MongoDB.Driver.Core.Misc.StreamExtensionMethods.ReadBytesAsync(Stream stream, Byte[] buffer, Int32 offset, Int32 count, TimeSpan timeout, CancellationToken cancellationToken)
   at MongoDB.Driver.Core.Connections.BinaryConnection.ReceiveBufferAsync(CancellationToken cancellationToken)
   --- End of inner exception stack trace ---
   at MongoDB.Driver.Core.Connections.BinaryConnection.ReceiveMessageAsync(Int32 responseTo, IMessageEncoderSelector encoderSelector, MessageEncoderSettings messageEncoderSettings, CancellationToken cancellationToken)
   at MongoDB.Driver.Core.WireProtocol.CommandUsingQueryMessageWireProtocol`1.ExecuteAsync(IConnection connection, CancellationToken cancellationToken)
   at MongoDB.Driver.Core.Connections.IsMasterHelper.GetResultAsync(IConnection connection, CommandWireProtocol`1 isMasterProtocol, CancellationToken cancellationToken)
   at MongoDB.Driver.Core.Connections.ConnectionInitializer.InitializeConnectionAsync(IConnection connection, CancellationToken cancellationToken)
   at MongoDB.Driver.Core.Connections.BinaryConnection.OpenHelperAsync(CancellationToken cancellationToken)
   --- End of inner exception stack trace ---
   at MongoDB.Driver.Core.Connections.BinaryConnection.OpenHelperAsync(CancellationToken cancellationToken)
   at MongoDB.Driver.Core.Servers.ServerMonitor.InitializeConnectionAsync(CancellationToken cancellationToken)
   at MongoDB.Driver.Core.Servers.ServerMonitor.HeartbeatAsync(CancellationToken cancellationToken)", LastHeartbeatTimestamp: "2021-03-14T22:18:27.4350973Z", LastUpdateTimestamp: "2021-03-14T22:18:27.4350976Z" }, { ServerId: "{ ClusterId : 1, EndPoint : "Unspecified/mongo2:27017" }", EndPoint: "Unspecified/mongo2:27017", ReasonChanged: "Heartbeat", State: "Disconnected", ServerVersion: , TopologyVersion: , Type: "Unknown", HeartbeatException: "MongoDB.Driver.MongoConnectionException: An exception occurred while opening a connection to the server.
 ---> System.TimeoutException: Timed out connecting to 172.31.128.202:27017. Timeout was 00:00:30.
   at MongoDB.Driver.Core.Connections.TcpStreamFactory.ConnectAsync(Socket socket, EndPoint endPoint, CancellationToken cancellationToken)
   at MongoDB.Driver.Core.Connections.TcpStreamFactory.CreateStreamAsync(EndPoint endPoint, CancellationToken cancellationToken)
   at MongoDB.Driver.Core.Connections.BinaryConnection.OpenHelperAsync(CancellationToken cancellationToken)
   --- End of inner exception stack trace ---
   at MongoDB.Driver.Core.Connections.BinaryConnection.OpenHelperAsync(CancellationToken cancellationToken)
   at MongoDB.Driver.Core.Servers.ServerMonitor.InitializeConnectionAsync(CancellationToken cancellationToken)
   at MongoDB.Driver.Core.Servers.ServerMonitor.HeartbeatAsync(CancellationToken cancellationToken)", LastHeartbeatTimestamp: "2021-03-14T22:19:25.9946242Z", LastUpdateTimestamp: "2021-03-14T22:19:25.9946246Z" }] }.
	"connections" : {
		"current" : 1142,
		"available" : 50058,
		"totalCreated" : 7653175,
		"active" : 3
	},
	"electionMetrics" : {
		"stepUpCmd" : {
			"called" : 0,
			"successful" : 0
		},
		"priorityTakeover" : {
			"called" : 1,
			"successful" : 1
		},
		"catchUpTakeover" : {
			"called" : 0,
			"successful" : 0
		},
		"electionTimeout" : {
			"called" : 0,
			"successful" : 0
		},
		"freezeTimeout" : {
			"called" : 0,
			"successful" : 0
		},
		"numStepDownsCausedByHigherTerm" : 0,
		"numCatchUps" : 0,
		"numCatchUpsSucceeded" : 0,
		"numCatchUpsAlreadyCaughtUp" : 1,
		"numCatchUpsSkipped" : 0,
		"numCatchUpsTimedOut" : 0,
		"numCatchUpsFailedWithError" : 0,
		"numCatchUpsFailedWithNewTerm" : 0,
		"numCatchUpsFailedWithReplSetAbortPrimaryCatchUpCmd" : 0,
		"averageCatchUpOps" : 0
	},
localThreshold

[Assistant]
Text:Hi, Nadeem and Roger,Thank you to each of you for reaching out to us. We have reviewed the log messages provided by both of you and we do not see evidence of CSHARP-3302. CSHARP-3302 was fixed in MongoDB .NET/C# driver v2.11.6 and v2.12.0. As well CSHARP-3302 is evidenced by heartbeats becoming stuck (LastHeartbeatTimestamp and LastUpdateTimestamp not updating) while one member shows that it is in the middle of processing a heartbeat.Server selection timeouts can occur for a wide variety of reasons and is most often the result of network connectivity issues between your client application and the cluster. In both the log lines provided, we see that the client application is unable to reach any of the cluster members due to network timeouts.We recommend verifying network connectivity and configuration, especially firewalls and connection limits and similar issues that could prevent your client application from successfully connecting with your cluster.Sincerely,
James
Code:LastHeartbeatTimestampLastUpdateTimestamp

[Assistant]
Text:James,Thanks for the review.  While I cannot rule out a network issue, our instances themselves report no intra-node dropouts, changes of primary, or timeouts.  All of our applications are run with internal load balancers and EC2 instances on the same VPC as the Mongo ec2 instances.  We do have some heavy .AggregateAsync<TModel>(pipeline, new AggregateOptions { BatchSize = 8000, AllowDiskUse = true })) operations, and continue to optimize things there.That said, we just saw another error that was thrown at the start of the contemporaneous CompositeServerSelector timeouts that may provide additional insights, as it seems strictly within the driver as a NullRefWe typically have between 1400-4000 connections open to the db, and have followed all the thread/socket/heap/ulimit settings pointers to make sure instances aren’t having socket starvation.Thanks again,
Roger
Code:.AggregateAsync<TModel>(pipeline, new AggregateOptions { BatchSize = 8000, AllowDiskUse = true }))CompositeServerSelectorSystem.NullReferenceException: Object reference not set to an instance of an object.
  Module "MongoDB.Driver.Core.Servers.ServerMonitor", in CancelCurrentCheck
  Module "MongoDB.Driver.Core.Servers.Server", in HandleBeforeHandshakeCompletesException
  Module "MongoDB.Driver.Core.Servers.Server", in GetChannelAsync
  Module "MongoDB.Driver.Core.Operations.RetryableReadContext", in InitializeAsync
  Module "MongoDB.Driver.Core.Operations.RetryableReadContext", in CreateAsync
  Module "MongoDB.Driver.Core.Operations.AggregateOperation`1", in ExecuteAsync
  Module "MongoDB.Driver.OperationExecutor+<ExecuteReadOperationAsync>d__3`1", in MoveNext
  Module "MongoDB.Driver.MongoCollectionImpl`1+<ExecuteReadOperationAsync>d__98`1", in MoveNext
  Module "MongoDB.Driver.MongoCollectionImpl`1+<AggregateAsync>d__22`1", in MoveNext
  Module "MongoDB.Driver.MongoCollectionImpl`1+<UsingImplicitSessionAsync>d__106`1", in MoveNext


[System] You are an assistant of MongoDB Community who is responsible for answering the questions related with MongoDB.

[System] The following conversation has title: C# .NET Core 3.1 - Driver (2.11.1) - Slow ToList() data manifestation and tags: ['dot-net']

[User]
Text:Hello,
I have a performance issue that I can’t ignore.
I have a collection with 1000 document. This collection will not grow so the number is stable.
Each document weight 1kb. A single document has one array of subdocument and some other properties.What I do is:The result of the query operation in MongoDbCompass is 1ms for 200 document and its super ok.
The result of the ToList() of the documents is 10 seconds.This happen even with property not inside an array.What can I do ?
ThanksEdit
I have indexes in place for the properties I need to search for.
Also this result are from localhost:27017, so all in local.I tested with the FindSync() and FindAsync() and I get the same results.
I tried .Skip(n) and Limit(n + 20) and the performance for 20 documents are 1.5 second. A lot.
Code:var result = db.collection("A")
            .Aggregate()
            .Match(Builders<T>.Filter.Eq("<ArrayName>.<PropertyName>", "name"))
            .ToList();

[Assistant]
Text:Can you run the same query in the Mongo shell, mongo and see if you get similar results? You should also try and run the explain() for the query and post it here.the explain docs are here.
Code:mongoexplain()explain

[User]
Text:Hello Joe,
thanks for the reply.I run ‘db.collection.find(…)’ and got the results. The performance was strictly bettere than the ToList()I also run the ‘db.collection.find().explain()’ and this is the result:
Code:{
queryPlanner: {
plannerVersion: 1,
namespace: 'FirstCollection.Pokemon',
indexFilterSet: false,
parsedQuery: { 'moves.name': { '$eq': 'thunder' } },
winningPlan: {
  stage: 'FETCH',
  inputStage: {
    stage: 'IXSCAN',
    keyPattern: { 'moves.name': 1 },
    indexName: 'MovesName',
    isMultiKey: true,
    multiKeyPaths: { 'moves.name': [ 'moves' ] },
    isUnique: false,
    isSparse: false,
    isPartial: false,
    indexVersion: 2,
    direction: 'forward',
    indexBounds: { 'moves.name': [ '["thunder", "thunder"]' ] }
  }
},
    rejectedPlans: []
},
executionStats: {
executionSuccess: true,
nReturned: 232,
executionTimeMillis: 0,
totalKeysExamined: 232,
totalDocsExamined: 232,
executionStages: {
  stage: 'FETCH',
  nReturned: 232,
  executionTimeMillisEstimate: 0,
  works: 233,
  advanced: 232,
  needTime: 0,
  needYield: 0,
  saveState: 0,
  restoreState: 0,
  isEOF: 1,
  docsExamined: 232,
  alreadyHasObj: 0,
  inputStage: {
    stage: 'IXSCAN',
    nReturned: 232,
    executionTimeMillisEstimate: 0,
    works: 233,
    advanced: 232,
    needTime: 0,
    needYield: 0,
    saveState: 0,
    restoreState: 0,
    isEOF: 1,
    keyPattern: { 'moves.name': 1 },
    indexName: 'MovesName',
    isMultiKey: true,
    multiKeyPaths: { 'moves.name': [ 'moves' ] },
    isUnique: false,
    isSparse: false,
    isPartial: false,
    indexVersion: 2,
    direction: 'forward',
    indexBounds: { 'moves.name': [ '["thunder", "thunder"]' ] },
    keysExamined: 232,
    seeks: 1,
    dupsTested: 232,
    dupsDropped: 0
  }
  }
 },
serverInfo: {
host: 'DESKTOP-CS3UEH8',
port: 27017,
version: '4.4.0',
gitVersion: '563487e100c4215e2dce98d0af2a6a5a2d67c5cf'
 },
 ok: 1
}

[Assistant]
Text:Can you post the output of .explain("executionStats"). This will give a more detailed report. I can see you are using an index stage: 'IXSCAN' which is good. What we are trying to do here is eliminate the possibility that the database is the bottleneck.  the executionStats parameter will give us a lot more detail about where the time is spent.
Code:.explain("executionStats")stage: 'IXSCAN'executionStats

[User]
Text:In the previous post if you scroll down the section code you can see the “executionStats”.
Sorry I didn’t specify that I used the .explain("executionStats")What I see slowing down it is the actual manifestation of the data.
I know I am trying to retrieve a List<BsonDocument> where each document has all the properties, array etc.
I can of course set a $projection to limit what to retrieve (and I will do eventually) but because I want to learn how mongodb works I am trying to understand why this is happening.
Code:.explain("executionStats")List<BsonDocument>

[Assistant]
Text:I see it now. So the actual query time is effectively 0. So your delay is not in the query or the database engine. Could it be n/w or client delays?
Code:

[User]
Text:I don’t think so. I am running all locally (mongodb is hosted in localhost:27017). All C# in a basic Console Application project with no client side.
I am doing like this just to understand the MongoDb C# Driver.So I don’t really know.
Code:

[Assistant]
Text:Put a time stamp either side of  the query on the client. It may just take a while to start your program. How long does it take from the program side to run the query.
Code:

[User]
Text:So, as I wrote I am doing this in a ConsoleApplication NetcoreApp 3.1.
I executed 2 different ways of querying, one with FindSync() the other with Aggregate().Match().The first one (FindSync):
Capture1672×494 10.4 KBThe second one (Aggregate):
Capture11628×485 10.8 KB
Code:FindSync()Aggregate().Match()

[Assistant]
Text:I am going to ask my C# colleague @yo_adrienne to take a look. She is based in Nevada so it will be a few hours.
Code:

[Assistant]
Text:Hi @Andrea_Zanini!Can you try your queries but with ToListAsync()?And if possible, can you also log out the execution stats?
Code:ToListAsync()

[User]
Text:Hello, sorry for the late answer.I tried the same thing with the await query.ToListAsync(); but even with that the time it takes for manifest the data is the same.For the execution stats do you mean what @Joe_Drumgoole asked me? Or I can, with C# code, somehow use the execution stats for the ToListAsync() operation?
Code:await query.ToListAsync();ToListAsync()

[Assistant]
Text:Hi All,I am experiencing the same issue. It’s not a matter of a big number of documents retrieved by the query but when doing the tolist(), it takes around 20 seconds to materialize them. Do you have any workaround or estimation for the fix? We also tried with the newest mongoDb driver version, but the issue is still there either using tolist or toListAsync. Please help
Code:

[User]
Text:Hello Sergio,
I didn’t found the cause of the problem and how to solve it unfortunately.What I did to go on with the project was start from the scratch and rebuild my document class with all the BsonAttribute to define via code what type are the property of the document (even if, when declared, have already the type)
Example:I changed a lot, more that I wanted to my document, but now the manifestation time it’s what I expected to be.I didn’t close the issue because I think there is something spooky around it.
Code:public class Example {
    [BsonId]
    [BsonRepresentation(BsonType.ObjectId)]
    public Guid Id {get; set; }

    [BsonRepresentation(BsonType.String)]
    public string Name {get; set; }
}

[Assistant]
Text:Hi Andrea,Thanks for your response. I tried that but still having the same issue toList is extremely slow:Any other ideas on this?
Code:        var query = collection.Aggregate(new AggregateOptions { AllowDiskUse = true })
            .Match(matching_criteria)
            .Group(grouping_criteria)
            .Sort(sorting_criteria)
            .Project(projection)
            .As<DOCUMENT>();

        var result = query.ToList();

[Assistant]
Text:Hi,I’m experiencing a similar performance overhead with the client for 1667 results.
Time in Compass : Actual Query Execution Time (ms):120
C# driver: around 6000 msAny update on this?
Code:

[Assistant]
Text:I am going to get some C# experts to check this one out.
Code:

[Assistant]
Text:In my case, the time seems to be in the serialization
It’s returning 1667 instances of Entity, each one with 500 instances of Bar and 150 instances of Foo
Code:   public class Entity
{
	public Guid Id { get; set; }
	public List<Bar> BarValues { get; set; }
	public List<Foo> FooValues { get; set; }
}

public class Bar
{
	public Guid Id { get; set; }
	public Guid B { get; set; }
	public Guid C { get; set; }
}

public class Foo
{
	public Guid Id { get; set; }
	public Guid B { get; set; }
	public object C { get; set; }
}

[Assistant]
Text:@Andrea_Zanini, @Sergio_Fiorillo, @Joao_Passos:There are still many factors that could be affecting these times, so I’d like to ask a few more questions regarding your respective scenarios:The object models collectively posted here seem straightforward, so the deserialization shouldn’t be an issue.Additionally, regarding these observations:The result of the query operation in MongoDbCompass is 1ms for 200 document and its super ok.
The result of the ToList() of the documents is 10 seconds .Time in Compass : Actual Query Execution Time (ms):120
C# driver: around 6000 msI’d like to quickly explain why this may be:When making a call to db.GetCollection(), this is usually ~8ms, as @Andrea_Zanini’s screenshots show:The first one (FindSync):The second one (Aggregate):When creating the Aggregate queries, it’s important to note that this doesn’t result in the first batch being retrieved; it’s only in-memory and doesn’t go out on the wire yet. Calling query.ToList(); takes the longest now because it has to retrieve the first batch (~600ms based on the FindSync log in Andrea’s first screenshot), PLUS all subsequent batches. This is why the total times are 8.5 seconds or higher.Compass reports query execution time is only 120ms because that only considers the query time on the server. It doesn’t include the time on the wire nor the deserialization from BSON to C# objects.So, some options:If you find that ping time is your bottleneck, your wait time is probably due to the amount of roundtrips that are required to retrieve the batches. Based on the earlier example of 9.1 seconds grand total execution time and ~600ms per batch, that’s about 15 round trips to the server (9.1s / 600ms).Possible solution to ping issue is to locate your app servers closer to the cluster that you’re querying.If you find that bandwidth is your bottleneck, your wait time is probably due to the time it takes to transmit each 15mb batch across the wire, again, around 15 times.Possible solution to bandwidth issue is to reduce the amount of data being retrieved, via a projection (like @Sergio_Fiorillo appears to be doing), and/or enabling wire protocol compression in your connection string or via code.Finally, if all else fails and it still appears to be a deserialization issue, we’d love to see a reproduction of it happening, ideally with some test data. I know it might be additional work, but even a small repo with this information helps us immensely in being able to debug the exact issue you may be having!Thanks for your patience! Looking forward to hearing from you and seeing if these possible solutions help.
Code:db.GetCollection()query.ToList();


[System] You are an assistant of MongoDB Community who is responsible for answering the questions related with MongoDB.

[System] The following conversation has title: How to delete a specific nested subdocument completely from an document and tags: ['aggregation', 'queries', 'node-js']

[User]
Text:i have the following documenti wanted to remove the nested address document completely but somehow leaves me with that id value, instead of being completely empty.i did something like this:but somehow it tends to delete both the nested address object elements. and I’m left with something like this:what i’d ideally want is something like this:
i’d want to delete specific address only and also, remove that subdocument from the nested array subdocuments. Something like this:lets say i want to delete the second nested documents, then the final documents should look like this:thank you kindly.
Code:{
        "_id" : ObjectId("605a62eadefa2a09797f1ae3"),
        "address" : [
                {
                        "_id" : ObjectId("605a62eadefa2a09797f1ae4"),
                        "street" : "King AS",
                        "state" : "CA",
                        "zip" : 12111
                },
                {
                        "_id" : ObjectId("605a62f9defa2a09797f1ae5"),
                        "street" : "123 Leon Street",
                        "state" : "CA",
                        "zip" : 12121
                }
        ],
        "firstName" : "James",
        "__v" : 1
}
findOneAndUpdate({ "_id": ObjectId("605a62eadefa2a09797f1ae3"), }, { address: { $elemMatch: {"_id": ObjectId("605a62f9defa2a09797f1ae5")} } }, {$unset:{address: ""}})

address: [ { _id: 605a697be0f5e50a3561dc44 } ]
{
        "_id" : ObjectId("605a62eadefa2a09797f1ae3"),
        "address" : [
                {
                        "_id" : ObjectId("605a62eadefa2a09797f1ae4"),
                        "street" : "King AS",
                        "state" : "CA",
                        "zip" : 12111
                }
        ],
        "firstName" : "James",
        "__v" : 1
}

[Assistant]
Text:Hi again
the answer is driven from this postSincerely,
Code:find({
  "_id": ObjectId("605a62eadefa2a09797f1ae3")
},
{
  address: {
    "$elemMatch": {
      "$ne": [
        "_id",
        ObjectId("605a62f9defa2a09797f1ae5")
      ]
    }
  }
})

[User]
Text:hello,the statement you provided does not remove the nested document.
its only outputting.Is there any other way?
Code:

[Assistant]
Text:My bad, sorry
there you go
Code:.update({
  "_id": ObjectId("605a62eadefa2a09797f1ae3")
},
{
  "$pull": {
    "address": {
      "_id": ObjectId("605a62f9defa2a09797f1ae5")
    }
  }
})

[User]
Text:@Imad_Bouteraa Thank you so much brother. I really appreciate you taking time to help me. Your steps really guided me in finishing up my personal project. It means a lot.So for the answer I think what you wrote was on the right track, but when I tried it did not work,
so I just looked up $pull and looks like we do not have to pass the  _id of the document when modifying the nested array sub documents.Your answer definitely helped tho.  Thank you again:so looks like we can get rid of the document _id and only worry about the nested document  _id
and add {multi:true} at the end of the query, like so:
Code:.update(
{},
{
  "$pull": {
    "address": {
      "_id": ObjectId("605a62f9defa2a09797f1ae5")
    }
  },
{
  multi: true
}
})

[Assistant]
Text:Well, without the _id in the query. mongodb will scan the whole collection and “technically” updates every document by removing addresses matching "_id": ObjectId("605a62f9defa2a09797f1ae5").
However if you include "_id": ObjectId("605a62eadefa2a09797f1ae3") mongodb will use the "_id" index and directly targets THE matching document.
So, if you know the "_id" of the concerned document. you absolutely have to take advantage of the "_id" index.
Now, a lot depends on your context:Sincerely,
Code:_id"_id": ObjectId("605a62f9defa2a09797f1ae5")"_id": ObjectId("605a62eadefa2a09797f1ae3")"_id""_id""_id"


[System] You are an assistant of MongoDB Community who is responsible for answering the questions related with MongoDB.

[System] The following conversation has title: Installing MongoDB Cpanel and tags: ['server', 'containers', 'installation']

[User]
Text:Hi there,I followed the steps mentioned at this page: https://docs.mongodb.com/manual/tutorial/install-mongodb-on-red-hat/#install-mongodb-community-editionbut it didn’t work (please, see the below picture):
image2678×196 30 KB
It’s a CentOS 7.Warmest regards.
Code:

[Assistant]
Text:Hi there!What command was this the output of?Can you show me the output of:
ls -l /etc/yum.repos.d/mongodb*andcat /etc/yum.repos.d/mongodb*??Also is the machine behind a proxy that tunnels port 443? a web proxy? A VPN? On a campus or corporate network?
Code:

[Assistant]
Text:Hi @Abelardo_Leon_Gonzal and welcome in the MongoDB Community  !I just followed the steps from your link in a fresh CentOS 7 docker container and I was able to install the latest version of MongoDB (v4.4.3 currently) without any major issue.I just had to install vim with yum install vim because my container was just out of the box and I couldn’t start mongod using systemd or System V Init because this just doesn’t work in a docker container (needs more permissions) - but I was able to start a mongod manually with mkdir /tmp/db && mongod --dbpath /tmp/db and then connect to it from my host using docker exec -it <container-name> mongo.Just FYI, I started my CentOS 7 container with docker run --rm -it centos:7 bash.So I couldn’t reproduce your issue really here. I’m not sure what step is causing this issue. Could you please be more specific?Thanks,
Maxime.
Code:yum install vimmongodsystemdSystem V Initmongodmkdir /tmp/db && mongod --dbpath /tmp/dbdocker exec -it <container-name> mongodocker run --rm -it centos:7 bash

[User]
Text:Hi @Sheeri_Cabral,I run the following command: sudo yum install -y mongodb-org
as mentioned at that page.The output of the command: ls -l /etc/yum.repos.d/mongodb*
is:-rw-r–r-- 1 root root 200 Jan  5 09:56 /etc/yum.repos.d/mongodb-org-4.4.repo[mongodb-org-4.4]
name=MongoDB Repository
baseurl=https://repo.mongodb.org/yum/centos/$releasever/mongodb-org/4.4/x86_64/
gpgcheck=1
enabled=1
gpgkey=https://www.mongodb.org/static/pgp/server-4.4.ascIt’s a VPS hosting.Thanks for your help! Best regards.
Code:sudo yum install -y mongodb-orgls -l /etc/yum.repos.d/mongodb*

[User]
Text:Hi there,I have a VPS account which runs CentOS 7.When I run thesudo yum install -y mongodb-orgin order to install MongoDB to be used with my NodeJS app, it outputs the following lines:Loaded plugins: fastestmirror, langpacks, universal-hooks
Loading mirror speeds from cached hostfile
EA4                                                                                | 2.9 kB  00:00:00
cpanel-addons-production-feed                                                                                | 2.9 kB  00:00:00
cpanel-plugins                                                                                | 2.9 kB  00:00:00
base                                                                                | 3.6 kB  00:00:00
docker-ce-stable                                                                                | 3.5 kB  00:00:00
epel                                                                                | 4.7 kB  00:00:00
extras                                                                                | 2.9 kB  00:00:00
imunify360                                                                                | 2.7 kB  00:00:00
imunify360-rollout-1                                                                                | 3.0 kB  00:00:00
imunify360-rollout-2                                                                                | 3.0 kB  00:00:00
imunify360-rollout-3                                                                                | 3.0 kB  00:00:00
imunify360-rollout-4                                                                                | 3.0 kB  00:00:00
h ttps://repo.mongodb.org/yum/centos/7/mongodb-org/4.4/x86_64/repodata/repomd.xml: [Errno 14] HTTPS Error 404 - Not Found
Trying other mirror.
To address this issue please refer to the below wiki articleh ttps://wiki.centos.org/yum-errorsIf above article doesn’t help to resolve this issue please use h ttps://bugs.centos.org/.mysql-connectors-community                                                                                | 2.6 kB  00:00:00
mysql-tools-community                                                                                | 2.6 kB  00:00:00
mysql57-community                                                                                | 2.6 kB  00:00:00
remi-php74                                                                                | 3.0 kB  00:00:00
remi-safe                                                                                | 3.0 kB  00:00:00
ul                                                                                | 2.9 kB  00:00:00
ul_ipage                                                                                | 2.9 kB  00:00:00
updates                                                                                | 2.9 kB  00:00:00
No package mongodb-org available.
Error: Nothing to doroot@server.abelardolg.com [~]# ls -l /etc/yum.repos.d/mongodb*:-rw-r–r-- 1 root root 200 Jan  5 09:56 /etc/yum.repos.d/mongodb-org-4.4.repocat /etc/yum.repos.d/mongodb*:[mongodb-org-4.4]
name=MongoDB Repository
baseurl=https://repo.mongodb.org/yum/centos/$releasever/mongodb-org/4.4/x86_64/
gpgcheck=1
enabled=1
gpgkey=https://www.mongodb.org/static/pgp/server-4.4.ascThanks for your help and best regards.
Code:

[Assistant]
Text:h ttps://repo.mongodb.org/yum/centos/7/mongodb-org/4.4/x86_64/repodata/repomd.xml: [Errno 14] HTTPS Error 404 - Not FoundLooks like an Internet connection issue? Some firewall misconfiguration maybe? Looks like you can’t reach the repo.
Code:

[Assistant]
Text:Hi @Abelardo_Leon_Gonzal,The baseurl looks different to me - in the docs, it’s:baseurl=https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/4.4/x86_64/your file has ‘centos’ instead of ‘redhat’ - when I go to MongoDB Repositories I’m not seeing a centos option, but I do see a redhat one.Further, if I go to https://repo.mongodb.org/yum/centos/7/mongodb-org/4.4/x86_64/repodata/repomd.xml I get a 404 Not Found but if I change ‘centos’ to ‘redhat’ and go to:https://repo.mongodb.org/yum/redhat/7/mongodb-org/4.4/x86_64/repodata/repomd.xmlI see XML data.can you try changing your baseurl?
Code:

[User]
Text:Hi there,Thanks for replying.After I replacing “centos” by “redhat”, “$releaseever” by “7” and to run the above command, I got this message:Loaded plugins: fastestmirror, langpacks, universal-hooks
Loading mirror speeds from cached hostfile
…
No package mongodb-org available.
Error: Nothing to doMy mongodb-org-4.4.repo file:[mongodb-org-4.4]
name=MongoDB Repository
baseurl=https://repo.mongodb.org/yum/redhat/7/mongodb-org/4.4/x86_64/
gpgcheck=1
enabled=1
gpgkey=https://www.mongodb.org/static/pgp/server-4.4.ascBest regards.
Code:

[User]
Text:Hi there,Thanks for replying.It’s not related to an Internet connection issue. It’s my fault because I made some typos in the url. I fixed them but it still continues with no be installed.Best regards.
Code:

[Assistant]
Text:Hi there!Did you clear the yum cache after making that change?yum clean allHopefully that will have the installation working!
Code:

[User]
Text:Hi there!I executed that command but a strange thing happens.When I re-run the following command:sudo yum install -y mongodb-orgits output was:Loaded plugins: fastestmirror, langpacks, universal-hooks
Determining fastest mirrors
…
EA4                                                                                | 2.9 kB  00:00:00
cpanel-addons-production-feed                                                                                | 2.9 kB  00:00:00
cpanel-plugins                                                                                | 2.9 kB  00:00:00I don’t understand why in this line appears centos again when I wrote redhat in my mongodb-org-4.4.repo file:http://mirrors.unifiedlayer.com/centos/7/os/x86_64/repodata/repomd.xml: [Errno 14] HTTP Error 403 -
ForbiddenIn fact, if I click on this link a xml appears. It seems valid.Trying other mirror.
To address this issue please refer to the below wiki article
Code:

[User]
Text:yum clean allI re-runned twice this command and the second time the following output was showed:
image619×1233 132 KBThe package #23/25 clearly statesmongodb-org-4.4/primary_dbbut the last message says:No package mongodb-org available.
Code:

[Assistant]
Text:Hi! I’m assuming that this also didn’t work? If I try to find mongo-org in the packages there, it doesn’t exist at
http://mirrors.unifiedlayer.com/centos/7/os/x86_64/Packages/What does this command result in?
cat /etc/issue
Code:

[User]
Text:cat /etc/issue\S
Kernel \r on an \m
Code:

[Assistant]
Text:Right, sorry, try these too?cat /proc/version
and
cat /etc/redhat-release
Code:

[User]
Text:Hi!
Yes, you correctly assumed that that also didn’t work.
Code:

[User]
Text:cat /proc/version outputs:Linux version 3.10.0-1127.19.1.el7.x86_64 (mockbuild@kbuilder.bsys.centos.org) (gcc version 4.8.5 20150623 (Red Hat 4.8.5-39) (GCC) ) #1 SMP Tue Aug 25 17:23:54 UTC 2020cat /etc/redhat-release:CentOS Linux release 7.9.2009 (Core)
Code:

[Assistant]
Text:OK, great. So you’re on CentOS.Can you try this?
sudo rm /etc/yum.repos.d/mongodb-org-4.4.repo
sudo yum clean allThen edit /etc/yum.repos.d/mongodb-org-4.4.repo and add in:
[mongodb-org-4.4]
name=MongoDB Repository
baseurl=https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/4.4/x86_64/
gpgcheck=1
enabled=1
gpgkey=https://www.mongodb.org/static/pgp/server-4.4.ascand then do
sudo yum install -y mongodb-organd see if that installs it?If that doesn’t work, you could try downloading the packages manually (there’s a link on the installation page) - MongoDB Repositories - specifically these packages and versions:
https://repo.mongodb.org/yum/redhat/7/mongodb-org/4.4/x86_64/RPMS/mongodb-org-4.4.3-1.el7.x86_64.rpm
https://repo.mongodb.org/yum/redhat/7/mongodb-org/4.4/x86_64/RPMS/mongodb-org-database-tools-extra-4.4.3-1.el7.x86_64.rpm
https://repo.mongodb.org/yum/redhat/7/mongodb-org/4.4/x86_64/RPMS/mongodb-org-mongos-4.4.3-1.el7.x86_64.rpm
https://repo.mongodb.org/yum/redhat/7/mongodb-org/4.4/x86_64/RPMS/mongodb-org-server-4.4.3-1.el7.x86_64.rpm
https://repo.mongodb.org/yum/redhat/7/mongodb-org/4.4/x86_64/RPMS/mongodb-org-shell-4.4.3-1.el7.x86_64.rpm
https://repo.mongodb.org/yum/redhat/7/mongodb-org/4.4/x86_64/RPMS/mongodb-org-tools-4.4.3-1.el7.x86_64.rpm
https://repo.mongodb.org/yum/redhat/7/mongodb-org/4.4/x86_64/RPMS/mongodb-cli-1.9.1.x86_64.rpm
https://repo.mongodb.org/yum/redhat/7/mongodb-org/4.4/x86_64/RPMS/mongodb-database-tools-100.2.1.x86_64.rpmDownload them via wget or curl, and then yum install FILENAME, for example:
sudo yum install -y mongodb-org-4.4.3-1.el7.x86_64.rpmI’m not sure why you’re having this issue - we’ve had a few people test on CentOS 7 and the instructions are working.
Code:

[Assistant]
Text:@Sheeri_Cabral
I just ran through on a centos:7 container, all looks good to me following the install instructions.@Abelardo_Leon_Gonzal
Also try the yum with the --noplugins  flag in case there is a yum-plugin messing with things.
Code:--noplugins


[System] You are an assistant of MongoDB Community who is responsible for answering the questions related with MongoDB.

[System] The following conversation has title: C# .NET Core 5.0 - Driver (2.12.0) - Sort ignore BsonElement attribute on projected class and tags: ['aggregation', 'dot-net']

[User]
Text:Hello, I am here to understand if I am doing something wrong or it’s the standard beheviour.I have a Document on the database defined with the classThe properties on MongoDb are traslated by the following global rulesSo all the properties is camelCase on the DbHere is the ProjectClassThis projectionClass is also registered as:When I read the data I am doing the follow:This does not sorting right.
If I use “Name” instead of “name” it will work.It is the expected behaviour ?
I am not using a Lamba expression because the sort field definition can be anything.Second question:Is
Project(Builders<Document>.Projection.Expression(a => new ProjectionDocument { ... }))
the same things as
.Project(a => new ProjectionDocument { ... })?Thanks in advance.
Kind Regards
Code:public class Document {
    public string Name { get; set; }
    public string Description{ get; set; }
    public List<string> Children { get; set; }
}
ConventionRegistry.Register("camelCase", new ConventionPack {
    new CamelCaseElementNameConvention()
}, _ => true);
public class ProjectionDocument {

    [BsonElement("name")]
    public string Name { get; set; }

    [BsonElement("description")]
    public string Description { get; set; }
}
BsonClassMap.RegisterClassMap<ProjectionDocument>(cm =>
{
   cm.AutoMap();
});
IMongoCollection<Document>().Aggregate()
    .Match(matchDefinition)
    .Project(a => new ProjectionDocument {
            Name = a.Name,
            Description = a.Description,
         }
    .Group(a => a.Name, a => new ProjectionDocument {
            Name = a.Key,
            Description = a.First().Description,
        }
    .Sort(Builders<ProjectionDocument>.Sort.Ascending("name"))
    .ToList();
Project(Builders<Document>.Projection.Expression(a => new ProjectionDocument { ... })).Project(a => new ProjectionDocument { ... })

[Assistant]
Text:Hi, Andrea,Thanks for reaching out to us with your question about mapping C# property names to database fields.Since you are using a Builder for the sort stage, you should refer to the field by its C# property name “Name” rather than by its database field name “name”. The CamelCaseElementNameConvention should take care of any C# property name to MongoDB field name conversions.ASIDE: Since CamelCaseElementNameConvention is configured for all types, you shouldn’t need to annotate your ProjectionDocument class with field names. Even [BsonElement] isn’t needed since we map all public get/set properties by default.Hope that helps. Let us know if you have any additional questions.Sincerely,
James
Code:BuilderCamelCaseElementNameConventionCamelCaseElementNameConventionProjectionDocument[BsonElement]

[User]
Text:Hello, James
thank you for your quick answer.So just for better understanding.
If I am sorting with a Builder the FieldDefinition refer to the name of the C# property, even if there is BsonElement or the property on the DB is camelCase (globally setted)?I’ve tried do the Sort directly to the IMongoCollection<Document> (with the Builder) and it works using the camelCase property name and not the C# property name.Can you explain me why this difference?Thanks again for your time!
Code:IMongoCollection<Document>

[User]
Text:Ok maybe it’s like:If I use the Builders<T> for sorting, projecting etc. the query works with the BsonDocument objInstead, if I use the lamba to perform this operations it’s like working in an upper level (C#) so thats why the property name valid is the C# class property name.I understood correctly?
Code:Builders<T>

[Assistant]
Text:Hi, Andrea,If you are working with Builders<BsonDocument> then you would use the field names in the database. If you are working with Builders<DOMAIN> (where DOMAIN is one of your strongly-typed C# classes) then you would use the C# property names.If you have encountered a case where you’re using your C# domain class but require using the database field names, please provide a self-contained repro so we can debug further as that is not the expected behaviour.Sincerely,
James
Code:Builders<BsonDocument>Builders<DOMAIN>DOMAIN

[User]
Text:Hello James,I will check but I’d like if you can check what I am actually doing with this example.I have a classBecause I have a dynamic filter (the user can search into the documents by keywords + value)
I have created a method for build the filterDefinition and it is like thisso when I call this BuilderMethod I dothis call use a strongly typed C# class (used also fo the insert operation with the global camelCase convention) and the properties names that I get fromis camelCase property name (because on MongoDb are like that) and it works greatly.But after I do theand addthe sortDefinition use the C# property name.Why the Match(filterDefinition) use the camelCase conventionad MongoDb properties?
Hope to have explained my questionKind Regards,
Andrea
Code:public class CSharpClass {
     public string Name {get; set; }
     public string Description {get; set; }
     .... (like 20 more properties)
}
	private static FilterDefinition<T> GetFilterDefinitionByFunction<T>(TreeParser.QueryTreeItem item, List<FilterDefinition<T>> other) where T : class
	{
		return item.Operator switch
		{
			Function.And => Builders<T>.Filter.And(other),
			Function.Or => Builders<T>.Filter.Or(other),
			Function.Equal => Builders<T>.Filter.Eq(Mappings.KeywordDbMapping[item.Keyword], GetStringOrNumber(item.Condition)),
			Function.Contains => double.TryParse(item.Condition, out _)
				? Builders<T>.Filter.Eq(Mappings.KeywordDbMapping[item.Keyword], GetStringOrNumber(item.Condition))
				: Builders<T>.Filter.Regex(Mappings.KeywordDbMapping[item.Keyword], $"(?i).*{item.Condition}.*"),

			Function.EqualOrGreaterThan => Builders<T>.Filter.Gte(Mappings.KeywordDbMapping[item.Keyword], GetStringOrNumber(item.Condition)),
			Function.EqualOrLesserThan => Builders<T>.Filter.Lte(Mappings.KeywordDbMapping[item.Keyword], GetStringOrNumber(item.Condition)),
			Function.LesserThan => Builders<T>.Filter.Lt(Mappings.KeywordDbMapping[item.Keyword], GetStringOrNumber(item.Condition)),
			Function.GreaterThan => Builders<T>.Filter.Gt(Mappings.KeywordDbMapping[item.Keyword], GetStringOrNumber(item.Condition)),
			Function.Size => Builders<T>.Filter.Size(Mappings.KeywordDbMapping[item.Keyword], GetIntNumber(item.Condition)),
			_ => Builders<T>.Filter.Empty
		};
	}
var filterDefinition = GetFilterDefinitionByFunction<CSharpClass>(result.TreeItem, ...);
Mappings.KeywordDbMapping[item.Keyword]
IMongoDbCollection<CSharpClass>.Aggregate().Match(filterDefinition)
.Project(a => new NewCSharpDocument {
     .....
})
Match(filterDefinition)

[Assistant]
Text:Hi, Andrea,Thank you for your additional clarifications. I dug into your code a bit more and believe I understand the root cause of the problem.In your aggregation, you are projecting into ProjectionDocument, grouping those results by Name into a new ProjectionDocument, and then attempting to sort those results. Our LINQ provider isn’t smart enough to realize that you’ve implicitly renamed Name to _id in the grouping stage.This is probably somewhat confusing without a concrete example. Let’s consider the following aggregation…ASIDE: In the .NET/C# driver you can see how we translate any query into MQL by calling ToString() on the query.The resulting aggregation is:Note the output of the $group stage is a set of documents of the form {_id: <<STRING>>, Description: <<STRING>>}. There is no mention of the name field in the output of the $group stage and thus the $sort stage is a no op.Let’s consider a slightly different, but equivalent aggregation. Notably we use Name = a.First().Name rather than Name = a.Key:The resulting MQL is:The output of the $group stage now contains documents of the form {_id: <<STRING>>, Name: <<STRING>>, Description: <<STRING>>}. The $sort stage is now able to sort on the Name field as desired.Note that the camelCaseConvention only plays a role in the $project where we are determining database field names from C# property names. e.g. { "$project" : { "Name" : "$name", "Description" : "$description", "_id" : 0 } } After the $project stage, we have transient documents with the correctly-cased field names that can be referred to by their C# property names.Hope this explanation helps.Sincerely,
James
Code:ProjectionDocumentNameProjectionDocumentName_idToString()var query = coll.Aggregate()
                .Match(Builders<Document>.Filter.Empty)
                .Project(a => new ProjectionDocument
                {
                    Name = a.Name,
                    Description = a.Description,
                })
                .Group(a => a.Name, a => new ProjectionDocument
                {
                    Name = a.Key,
                    Description = a.First().Description,
                })
                .Sort(Builders<ProjectionDocument>.Sort.Ascending("name"));

Console.WriteLine(query.ToString());
aggregate([
  { "$match" : { } },
  { "$project" : { "Name" : "$name", "Description" : "$description", "_id" : 0 } },
  { "$group" : { "_id" : "$Name", "Description" : { "$first" : "$Description" } } },
  { "$sort" : { "name" : 1 } }
])
$group{_id: <<STRING>>, Description: <<STRING>>}name$group$sortName = a.First().NameName = a.Keyvar query = coll.Aggregate()
                .Match(Builders<Document>.Filter.Empty)
                .Project(a => new ProjectionDocument
                {
                    Name = a.Name,
                    Description = a.Description,
                })
                .Group(a => a.Name, a => new ProjectionDocument
                {
                    Name = a.First().Name,
                    Description = a.First().Description,
                })
                .Sort(Builders<ProjectionDocument>.Sort.Ascending("Name"));

Console.WriteLine(query.ToString());
aggregate([
  { "$match" : { } },
  { "$project" : { "Name" : "$name", "Description" : "$description", "_id" : 0 } },
  { "$group" : { "_id" : "$Name", "Name" : { "$first" : "$Name" }, "Description" : { "$first" : "$Description" } } },
  { "$sort" : { "Name" : 1 } }
])
$group{_id: <<STRING>>, Name: <<STRING>>, Description: <<STRING>>}$sortNamecamelCaseConvention$project{ "$project" : { "Name" : "$name", "Description" : "$description", "_id" : 0 } }$project

[User]
Text:Hello James,thank you for your detailed clarifications.
Now I understood perfectly the behaviour!Thanks again,
Andrea
Code:


[System] You are an assistant of MongoDB Community who is responsible for answering the questions related with MongoDB.

[System] The following conversation has title: Npm mongodb 3.6.3 useUnifiedTopology throws MongoServerSelectionError with replicaSet and tags: ['node-js', 'connecting', 'typescript']

[User]
Text:Dears,When i updated to mongodb from 3.6.2 to 3.6.3 when i connect to the DB it throws error if useUnifiedTopology is set to trueHere is the snippet of the code (ommited username, password and db) using typescriptBut if useUnifiedTopology  is set to false, it gives me  warning , works fine and it gives me the results i expectedAny help about this?Edit: the problem only exists when using replica set (standalone)  when i disable replica set option in config it works fine
Code:import { MongoClient } from 'mongodb';

async function initDB() {
  const mongoClient = new MongoClient(
    'mongodb://***:***@192.168.45.20:27020/db?authSource=admin&readPreference=primaryPreferred&ssl=false', {
    useNewUrlParser: true,
    useUnifiedTopology: true
  })

  const client = await mongoClient.connect()
  const data = await client.db().collection('providers').find().toArray()
  return data
}

initDB().then((result) => {
  console.log(`result`, result)
}).catch((err) => {
  console.log(`err`, err)
});

MongoServerSelectionError: getaddrinfo ENOTFOUND bawq-server
    at Timeout._onTimeout (/mnt/d/work/playground/node_modules/mongodb/lib/core/sdam/topology.js:438:30)
    at listOnTimeout (internal/timers.js:554:17)
    at processTimers (internal/timers.js:497:7) {
  reason: TopologyDescription {
    type: 'ReplicaSetNoPrimary',
    setName: 'rs1',
    maxSetVersion: 1,
    maxElectionId: 7fffffff0000000000000001,
    servers: Map(1) { 'bawq-server:27020' => [ServerDescription] },
    stale: false,
    compatible: true,
    compatibilityError: null,
    logicalSessionTimeoutMinutes: null,
    heartbeatFrequencyMS: 10000,
    localThresholdMS: 15,
    commonWireVersion: 9
  }
}
useUnifiedTopology (node:2464) DeprecationWarning: current Server Discovery and Monitoring engine is deprecated, and will be removed in a future version. To use the new Server Discover and Monitoring
engine, pass option { useUnifiedTopology: true } to the MongoClient constructor.

[Assistant]
Text:I just upgraded locally from 3.5.x to latest 3.6.3 and was also unable to connect to my local MongoDB instance. I got the same errors. I thought something was wrong with my dev server. At least it’s good to know that I’m not the only one.  Back on 3.5 for now and it works.
Code:

[Assistant]
Text:I’m having the same issue when I use mongodb native driver 3.6.4. When I set useUnifiedTopology: false it doesn’t cause that selection error. I will downgrade to 3.5. Thanks @Nick for the tip!
Code:3.6.4useUnifiedTopology: false3.5


[System] You are an assistant of MongoDB Community who is responsible for answering the questions related with MongoDB.

[System] The following conversation has title: How to only get the array nested subdocuments with that document id and not having to iterate through it and tags: []

[User]
Text:lets say i have the id for the second nested object.how to get only the document that is related to that id and not the whole document?so far I have tried:and gotten:I would ideally want to have the nested documents, not just the id. Can anyone help me?
Thank you kindly
Code:{
        "_id" : ObjectId("605a3a82c8bbb404f4e6b643"),
        "address" : [
                {
                        "_id" : ObjectId("605a3a82c8bbb404f4e6b644"),
                        "street" : "123 Leon Street",
                        "state" : "WE",
                        "zip" : 11312
                },
                {
                        "_id" : ObjectId("605a3b3bc8bbb404f4e6b645"),
                        "street" : "123 King Street",
                        "state" : "WE",
                        "zip" : 99998
                }
        ],
        "firstName" : "Tetet",
        "__v" : 1
}
 "_id" : ObjectId("605a3b3bc8bbb404f4e6b645")
db.contacts.find({"_id" : ObjectId("605a3a82c8bbb404f4e6b643")}, {"address._id": ObjectId("605a3b3bc8bbb404f4e6b645")}).pretty()
{
        "_id" : ObjectId("605a3a82c8bbb404f4e6b643"),
        "address" : [
                {
                        "_id" : ObjectId("605a3b3bc8bbb404f4e6b645")
                },
                {
                        "_id" : ObjectId("605a3b3bc8bbb404f4e6b645")
                }
        ]
}

[Assistant]
Text:Hi,
with this query+projectionyou getis it what you want?Sincerely,
Code:find({
  "_id": ObjectId("605a3a82c8bbb404f4e6b643")
},
{
  address: {
    "$elemMatch": {
      "_id": ObjectId("605a3b3bc8bbb404f4e6b645")
    }
  }
})[
  {
    "_id": ObjectId("605a3a82c8bbb404f4e6b643"),
    "address": [
      {
        "_id": ObjectId("605a3b3bc8bbb404f4e6b645"),
        "state": "WE",
        "street": "123 King Street",
        "zip": 99998
      }
    ]
  }
]

[User]
Text:is there a way to just get
Code:{
        "_id": ObjectId("605a3b3bc8bbb404f4e6b645"),
        "state": "WE",
        "street": "123 King Street",
        "zip": 99998
}

[Assistant]
Text:is there a way to just getthere are many and morethis also works
Code:db.collection.aggregate([
  {
    "$match": {
      "_id": ObjectId("605a3a82c8bbb404f4e6b643")
    }
  },
  {
    "$unwind": "$address"
  },
  {
    "$match": {
      "address._id": ObjectId("605a3b3bc8bbb404f4e6b645")
    }
  },
  {
    "$replaceRoot": {
      "newRoot": "$address"
    }
  }
])db.collection.aggregate([
  {
    "$match": {
      "_id": ObjectId("605a3a82c8bbb404f4e6b643")
    }
  },
  {
    "$replaceRoot": {
      "newRoot": {
        "$first": {
          "$filter": {
            "input": "$address",
            "as": "item",
            "cond": {
              $eq: [
                "$$item._id",
                ObjectId("605a3b3bc8bbb404f4e6b645")
              ]
            }
          }
        }
      }
    }
  }
])


[System] You are an assistant of MongoDB Community who is responsible for answering the questions related with MongoDB.

[System] The following conversation has title: Why change v8 to spidermonkey in mongodb js engine? and tags: []

[User]
Text:i need explains very much. i love nodejs, and v8. nodejs js engine is v8.
Code:

[Assistant]
Text:Welcome to the MongoDB Community @anlex_N!There is a lengthy article in the MongoDB Engineer Journal which explains some of the technical reasoning: Code-generating Away the Boilerplate in Our Migration Back to Spidermonkey.This paragraph from the article provides a nice summary:SpiderMonkey has several qualities that make it the most suitable option for our needs. Most importantly, its process model is most like ours, with a single process for the browser and threads for tabs. This necessitates better tools for constraining memory and managing resource exhaustion. In addition, Firefox (and thereby SpiderMonkey) is available on the greatest number of platforms. In addition to its high performance JIT, it also has a baseline interpreter in C++ that ensures that any architecture capable of hosting a reasonable distribution of Linux can also run Firefox. And as icing on the cake, the Mozilla Foundation offers extended support releases of Firefox that offer security fixes for a year; annual maintenance affords us a substantially more manageable integration than the six-week fix cycles we had with V8.From an end-user point of view, the choice of JavaScript engine affects two broad usages: client-side and server-side. The legacy mongo shell is part of the MongoDB server codebase, so a given release of MongoDB will have the same embedded JavaScript engine in both of these binaries.Server-side JavaScript is generally discouraged (and often disabled) as there are significant security, concurrency, and performance caveats. The MongoDB query language has expanded in successive server releases to replace the majority of use cases where JavaScript would previously been required. The server-side eval command (db.eval() via the mongo shell) was deprecated in MongoDB 3.0 and removed in MongoDB 4.2. The limited contexts where server-side JavaScript can be used are not expected to support the full range of language features (or pace of change) as Node.js.However, for the client-side use case we have introduced a new MongoDB Shell (mongosh) which is built on top of the Node.js REPL. The new MongoDB shell is designed to be embeddable and extensible. You can install mongosh as a standalone download, but you’ll also find mongosh embedded in MongoDB Compass and third party tools (for example: JetBrains: Introducing MongoDB Shell in DataGrip).That’s a rather long explanation, but if you’re a fan of Node.js you should definitely check out mongosh and let us know if you have any feedback: How can we improve the MongoDB Shell?.Regards,
Stennie
Code:mongoevaldb.eval()mongomongoshmongoshmongoshmongosh

[User]
Text:as i know, firefox is written by rust, and your new mognsh is built on top of  nodejs repl, oh my god, nodejs is written by C++ mainly. i don’t want to learn rust that is very complex. i just learn and like C++. your mongo team use so many programming language, it is so wrong.
Code:

[Assistant]
Text:Hi @anlex_N,Can you provide more information on the use case or issue you are trying to solve?There is no need to learn the languages that applications or server processes are written in, unless you are planning to contribute to those software projects.If you are developing an application that connects to MongoDB, you would use a Supported Driver/Library in your preferred language framework. This does not require learning any additional programming languages aside from the main one you are using.If you want to explore data using a tool, you can use the new MongoDB Shell (which exposes an interactive command-line interface) or a more visual tool like MongoDB Compass. You do not need to learn Node.js to use the MongoDB Shell; that aspect is a feature for developers who want to extend functionality of their shell environment.Regards,
Stennie
Code:

[User]
Text:i am learning your mongodb source code. i think spidermonkey is not so very meaningful. i don’t want to learn another js engine. i want to contribute to you in the future.
although i can not master C++ 100%, but if i master rust, i would master c++ 100%. it wll cost me so long time. do you know?
by the way, based on your docs, your mongodb source code is written by c++ 11 syntax largely. c++ 20 is the stable release now. oh my god. your syntax is so old, and if written by latest c++ syntax, your source code can be decreased very much.
Code:

[Assistant]
Text:i am learning your mongodb source code. i think spidermonkey is not so very meaningful. i don’t want to learn another js engine. i want to contribute to you in the future.Hi @anlex_N,The JavaScript engine is only used in limited contexts. You can learn about the server source code without ever touching the code for the embedded JavaScript engine.If you are learning about the server source code, I would focus on a specific area or subsystem of interest. Working with the source code for a large project is more like reading short stories than sitting down with a novel where you read every chapter.by the way, based on your docs, your mongodb source code is written by c++ 11 syntax lI think you may be referring to the MongoDB C++ Driver which supports C++11 or newer.The definitive information for the server source code is on GitHub (mongodb/mongo). You can find the prerequisites (which may vary for major release branches) in docs/building.md. The current requirement is C++17, which is the most recent ISO standard before C++20.The build requirements for a mature product with an established codebase and many supported platforms cannot change as quickly as the latest language features, but the platform team does evaluate the benefits (and risks) of upgrading to newer prerequisites at the appropriate time.C++20 has been in development for a few years, but the language standard was only approved in Sept 2020 and published by ISO in Dec 2020. Adopting a new language standard also requires compilers with feature support, and many still only have partial/experimental C++20 support at this stage.I wish you luck in your further studies but I believe your original question on choice of JavaScript engines has been thoroughly addressed now.Regards,
Stennie
Code:mongodb/mongodocs/building.md

[User]
Text:webpack is my build system, nodejs is my server code, nativescript is my mobile code, those are based on v8. i wish mongodb js engine is v8 very much. i wish all in one SOLUTION. do you know, teacher?
@Stennie_X, how is v8 process model? i have searched in google, but can not find some material.
chromium have 4 process models, those are not benefit for you?
Code:


[System] You are an assistant of MongoDB Community who is responsible for answering the questions related with MongoDB.

[System] The following conversation has title: Maximum size of database or collection and tags: ['capacity-planning']

[User]
Text:Hello,
I’m new user and I’m studying MongoDB. I have installed MongoDB as a Docker container on a Linux device. This device sends documents which  contain information about some data, in different DBs of MongoDB. I would like to know what is the maximum size of the DB and of the collections and what happens to the DB once that size is reached. Is the information overwritten?
I hope you can help me. Thank you
Code:

[Assistant]
Text:Hi Federica,The maximum size an individual document can be in MongoDB is 16MB with a nested depth of 100 levels.Edit: There is no max size for an individual MongoDB database.You can learn more about MongoDB limits and thresholds here: https://docs.mongodb.com/manual/reference/limits/
Code:

[User]
Text:Hi Ado,
I had seen the table but there are different parameters for the max size, it goes from 1 TB to 32 TB according to the Chunk Size and Average Size of Shard Key Values. I haven’t set either of these two parameters. What values should I consider?
Sorry for the requests but I have some difficulties to understand how MongoDB works.
Thank you
Code:

[Assistant]
Text:Hey Federica,Sorry I made a mistake in my original reply. As far as the database size goes, there is technically no limit for how big an individual database can be.If you’re using MongoDB Atlas, you won’t ever have to worry about database size as it will scale as you grow.
Code:

[Assistant]
Text:Welcome to the MongoDB Community @FEDERICA_BO!I would like to know what is the maximum size of the DB and of the collections and what happens to the DB once that size is reached.Practical limits & thresholds to consider are documented in the  MongoDB Limits and Thresholds page that @ado shared earlier.I had seen the table but there are different parameters for the max size, it goes from 1 TB to 32 TB according to the Chunk Size and Average Size of Shard Key Values. I haven’t set either of these two parameters. What values should I consider?The table you are referring to is specific to Sharding Existing Collection Data Size and per the Important callout for this section, this limitation only applies to initial sharding:These limits only apply for the initial sharding operation. Sharded collections can grow to any size after successfully enabling sharding.Collections are generally sharded well before reaching those collection sizes. Rebalancing TBs of data will take a long while even with great server & network resources. It is best to shard well before it becomes urgent to do so, as data migration will add even more load to a deployment that is already stressed.The estimation of these limits is explained just above the table. When a collection is initially sharded, a calculation is done to determine how to split existing data into chunk ranges based on the shard key with each range representing data sizes close to the configured Chunk Size. A list of initial split points is currently returned in a single BSON document which is subject to the 16MB document size limit.What that table is trying to estimate is the size of collections that can be sharded based on varying shard key sizes or chunk sizes:Use the following formulas to calculate the theoretical maximum collection size.maxSplits = 16777216 (bytes) /  maxCollectionSize (MB) >  maxSplits * (chunkSize / 2)Chunk Size and Average Size of Shard Key Values. I haven’t set either of these two parameters. What values should I consider?Chunk Size should be left at the default value (64MB) unless you have specific motivation to change this (for example, if you waited too long to shard and need a larger chunk size for initial sharding  ). There is no configuration for shard key size: the average size of shard key values will depend on the field(s) you choose for your shard key index and the associated values in the collection being sharded.For more background on practical vs theoretical limits, please see my response on this earlier discussion: Database and collection limitations - #2 by Stennie.If you are concerned about managing capacity planning and scaling yourself, MongoDB Atlas would be a significant help with features like Cluster Auto-Scaling and the ability to adjust cluster resources based on your current requirements.Regards,
Stennie
Code:

[User]
Text:Thank you guys for you explanation. You have been very kind. Now the topic is clearer.
Code:


[System] You are an assistant of MongoDB Community who is responsible for answering the questions related with MongoDB.

[System] The following conversation has title: Cannot store Java enum values in MongoDB and tags: ['java']

[User]
Text:Hi,
I have a codec provider for enum suggested by https://dev.to/harithay:EnumCodecProvider was registered this way:During debugging I can see that all BSON types are processed by EnumCustomProvider except my
enum ShipmentStatus:Could you give me an advice what is missing in the code? How we can force MongoDB to process the enums using custom ShipmentStatusCodec?Thanks,
Elena
Code:public class EnumCodecProvider implements CodecProvider {
    @Override
    public <T> Codec<T> get(Class<T> clazz, CodecRegistry registry) {
        log.info("Inside EnumCodecProvider: {}", clazz.getSimpleName());
        if (clazz == ShipmentStatus.class) {
            return (Codec<T>) new ShipmentStatusCodec();
        }
        return null;
    }
}
CodecRegistry codecRegistry = CodecRegistries.fromRegistries(
				CodecRegistries.fromProviders(new EnumCodecProvider()),
				MongoClients.getDefaultCodecRegistry()
		);

		MongoClientSettings settings = MongoClientSettings.builder()
				.uuidRepresentation(UuidRepresentation.STANDARD)
				.retryReads(true)
				.retryWrites(true)
				.codecRegistry(codecRegistry)
				.applyConnectionString(connectionString).build();
		return MongoClients.create(settings);
10:32:15.538 INFO  6ad6a0f68e2d c.t.t.p.c.v.codec.EnumCodecProvider - Inside EnumCodecProvider: Document
10:32:15.540 INFO  6ad6a0f68e2d c.t.t.p.c.v.codec.EnumCodecProvider - Inside EnumCodecProvider: MaxKey
10:32:15.540 INFO  6ad6a0f68e2d c.t.t.p.c.v.codec.EnumCodecProvider - Inside EnumCodecProvider: BsonRegularExpression
10:32:15.541 INFO  6ad6a0f68e2d c.t.t.p.c.v.codec.EnumCodecProvider - Inside EnumCodecProvider: Integer
10:32:15.541 INFO  6ad6a0f68e2d c.t.t.p.c.v.codec.EnumCodecProvider - Inside EnumCodecProvider: Date
10:32:15.541 INFO  6ad6a0f68e2d c.t.t.p.c.v.codec.EnumCodecProvider - Inside EnumCodecProvider: BsonDbPointer
10:32:15.541 INFO  6ad6a0f68e2d c.t.t.p.c.v.codec.EnumCodecProvider - Inside EnumCodecProvider: Symbol
10:32:15.541 INFO  6ad6a0f68e2d c.t.t.p.c.v.codec.EnumCodecProvider - Inside EnumCodecProvider: ObjectId
10:32:15.541 INFO  6ad6a0f68e2d c.t.t.p.c.v.codec.EnumCodecProvider - Inside EnumCodecProvider: BsonTimestamp
10:32:15.541 INFO  6ad6a0f68e2d c.t.t.p.c.v.codec.EnumCodecProvider - Inside EnumCodecProvider: MinKey
10:32:15.541 INFO  6ad6a0f68e2d c.t.t.p.c.v.codec.EnumCodecProvider - Inside EnumCodecProvider: String
10:32:15.541 INFO  6ad6a0f68e2d c.t.t.p.c.v.codec.EnumCodecProvider - Inside EnumCodecProvider: List
10:32:15.542 INFO  6ad6a0f68e2d c.t.t.p.c.v.codec.EnumCodecProvider - Inside EnumCodecProvider: Binary
10:32:15.542 INFO  6ad6a0f68e2d c.t.t.p.c.v.codec.EnumCodecProvider - Inside EnumCodecProvider: Double
10:32:15.543 INFO  6ad6a0f68e2d c.t.t.p.c.v.codec.EnumCodecProvider - Inside EnumCodecProvider: Code
10:32:15.543 INFO  6ad6a0f68e2d c.t.t.p.c.v.codec.EnumCodecProvider - Inside EnumCodecProvider: Long
10:32:15.543 INFO  6ad6a0f68e2d c.t.t.p.c.v.codec.EnumCodecProvider - Inside EnumCodecProvider: Boolean
10:32:15.543 INFO  6ad6a0f68e2d c.t.t.p.c.v.codec.EnumCodecProvider - Inside EnumCodecProvider: Decimal128
10:32:15.543 INFO  6ad6a0f68e2d c.t.t.p.c.v.codec.EnumCodecProvider - Inside EnumCodecProvider: CodeWithScope
10:32:15.544 INFO  6ad6a0f68e2d c.t.t.p.c.v.codec.EnumCodecProvider - Inside EnumCodecProvider: BsonUndefined

[Assistant]
Text:Hi @Elena_Alexandrova,Thanks for reaching out.  I tried to reproduce your results with the following test:but it printsas expected.  Can you provide a complete, minimal reproducer that demonstrates what you’re seeing?Regards,
Jeff
Code:public class EnumCodecProviderTest {
public static void main(String[] args) {
    CodecRegistry codecRegistry = CodecRegistries.fromRegistries(
            CodecRegistries.fromProviders(new EnumCodecProvider()),
            MongoClients.getDefaultCodecRegistry()
    );

    // I'm assuming that you are using Document as the container, but it's
    // not clear from your description
    Document doc = new Document("status", ShipmentStatus.SHIPPED);

    // this is essentially what happens when using MongoClient, but avoids
    // the need to actually use a MongoClient
    String json = doc.toJson(codecRegistry.get(Document.class));

    System.out.println(json);
}

public static class EnumCodecProvider implements CodecProvider {
    @Override
    public <T> Codec<T> get(Class<T> clazz, CodecRegistry registry) {
        if (clazz == ShipmentStatus.class) {
            //noinspection unchecked
            return (Codec<T>) new ShipmentStatusCodec();
        }
        return null;
    }

}

public static class ShipmentStatusCodec implements Codec<ShipmentStatus> {
    @Override
    public ShipmentStatus decode(BsonReader reader, DecoderContext decoderContext) {
        return ShipmentStatus.valueOf(reader.readString());
    }

    @Override
    public void encode(BsonWriter writer, ShipmentStatus value, EncoderContext encoderContext) {
        writer.writeString(value.name());
    }

    @Override
    public Class<ShipmentStatus> getEncoderClass() {
        return ShipmentStatus.class;
    }
}

public enum ShipmentStatus {
    SHIPPED
}
}
{"status": "SHIPPED"}

[User]
Text:Thanks, @Jeffrey_Yemin.
I used ReactiveMongoRepository to store my data.Actually, I’ve already found the solution that works for me. I used the custom converters.
Code:@Configuration
@Slf4j
public class MongoDBConfig extends AbstractReactiveMongoConfiguration {
	@Override
	protected void configureConverters(MongoCustomConversions.MongoConverterConfigurationAdapter adapter) {
		adapter.registerConverter(new ShipmentStatusReadConverter());
		adapter.registerConverter(new ShipmentStatusWriteConverter());
	}
}

@Slf4j
@Component
@WritingConverter
public class ShipmentStatusWriteConverter implements Converter<ShipmentStatus, String> {
    @Override
    public String convert(ShipmentStatus status) {
        log.info("Writing Converter called");
        return status.getValue();
    }
}

@Slf4j
@Component
@ReadingConverter
public class ShipmentStatusReadConverter implements Converter<String, ShipmentStatus> {
    @Override
    public ShipmentStatus convert(String value) {
        log.info("Reading Converter called");
        return ShipmentStatus.fromValue(value);
    }
}

@Slf4j
public enum ShipmentStatus {
    NEW("New"),
    PLANNED("Planned"),
    ASSIGNED("Assigned");

    private String value;

    ShipmentStatus(String value) {
        this.value = value;
    }

    public String value() {
        return this.value;
    }

    @JsonValue
    public String getValue() {
        return value;
    }

    @JsonCreator
    public static ShipmentStatus fromValue(String value) {
        for (ShipmentStatus e : ShipmentStatus.values()) {
            if (e.value.equalsIgnoreCase(value)) {
                return e;
            }
        }
        throw new UnsupportedEnumValueException(value, ShipmentStatus.class);
    }

    @Override
    public String toString() {
        return this.value;
    }
}