[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 over Ubuntu 22.04 and tags: ['sharding']

[User]
Text:Hello,These days Ubuntu published their new long term supported version, 22.04, and it is not possible to install mongodb because they don’t support libssl1.1 anymore:I googled it, but I did not find anywhere nobody who could solve this problem. Any ideas?
Thank you!
Code:The following packages have unmet dependencies:
 mongodb-org-mongos : Depends: libssl1.1 (>= 1.1.1) but it is not installable
 mongodb-org-server : Depends: libssl1.1 (>= 1.1.1) but it is not installable
 mongodb-org-shell : Depends: libssl1.1 (>= 1.1.1) but it is not installable

[Assistant]
Text:Are you following these directions?
Code:

[User]
Text:Yes, but it’s a dependency problem. I tried mongo 4.4 and 5.0, to no avail: same error on both.
Code:

[Assistant]
Text:Aha. I’m on 20.0x and haven’t upgraded to 22 yet. I’m sure @Stennie_X will have the answer!
Code:

[Assistant]
Text:This worked for me
Code:echo "deb http://security.ubuntu.com/ubuntu impish-security main" | sudo tee /etc/apt/sources.list.d/impish-security.list
sudo apt-get update
sudo apt-get install libssl1.1

[Assistant]
Text:Just apt installing openssl 1.1 sounds like a recipe for disaster.
Ubuntu 22.04 already has openssl 3 installed.
I think a MongoDB team member had best respond to this issue with a recommended path
… @Stennie_X ?
Code:

[Assistant]
Text:Hi folks,Ubuntu 22.04 was released less than a week ago so doesn’t have official MongoDB packages available yet. The build team is aware and will set up appropriate packaging & testing infrastructure to validate new packages.Relevant Jira issues to watch are:I don’t have a specific ETA to share at the moment, but I’d generally recommend waiting for essential software packages to be available before committing to major O/S upgrades.If you are an early adopter of a new O/S release, suggested interim workarounds would be:Run your MongoDB deployment on separate hosts with supported O/S versions (eg 20.04 LTS)Run MongoDB in a container/VM with a supported O/S versionUse a hosted version of MongoDB (eg MongoDB Atlas) so you have fewer direct dependencies on O/S updatesAll of these approaches use official binaries, so you are less likely to run into novel issues.For a development environment you could also consider:Building MongoDB from sourceTrying to install or build missing dependenciesHowever, I would be very wary of mixing & matching packages intended for different O/S versions (especially for a production environment) as those combinations have not been thoroughly tested.Regards,
Stennie
Code:

[User]
Text:Ok, thank you! Will wait for the support then. Out of ignorance, may I ask if generating a snap instead of a deb could solve the dependency problem and other possible library conflicts?
Code:

[Assistant]
Text:Thanks, It worked for me as well!!
Code:

[Assistant]
Text:Hi there, hope you’re doing well. I’m currently using MongoDB in Docker and it is good enough while waiting for new update from the MongoDB team.to start MongoDB (automatically restart):
sudo docker run -dp 27017:27017 -v local-mongo:/data/db --name local-mongo --restart=always mongoTo access into running local-mongo container:
sudo docker exec -it local-mongo shThen type mongo and you’re good to go!
Code:sudo docker run -dp 27017:27017 -v local-mongo:/data/db --name local-mongo --restart=always mongolocal-mongosudo docker exec -it local-mongo shmongo

[Assistant]
Text:This worked for me as well.  Still waiting for offcial release.
Code:

[Assistant]
Text:Can you drop the process of installing mongodb on docker ??
Code:

[Assistant]
Text:Hi Alexander, I’ve already posted the process above. I’ll re-post it in case you didn’t see it:
sudo docker run -dp 27017:27017 -v local-mongo:/data/db --name local-mongo --restart=always mongo
Code:sudo docker run -dp 27017:27017 -v local-mongo:/data/db --name local-mongo --restart=always mongo

[Assistant]
Text:Thank you. Will try it now
Code:

[Assistant]
Text:As a sidenote, you can still download some of the mongodb binaries from the official ubuntu repo (not recommended by mongodb though), if you just playing around it is fine imho. Example:You can see it skips libssl1.1
Code:sudo apt-get install mongo<tab>
mongocli                          mongodb-mongosh  ...
sudo apt-get install mongodb-mongosh
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
Recommended packages:
  libssl1.1

[Assistant]
Text:Is there any ETA on 22.04 packages? Or even RHEL 9?Any rough estimate? It’s the only blocker we have now for both distros.
Code:

[Assistant]
Text:Hey fellas.
Is there already any “official” solution to that problem?
I also struggle with Ubuntu 22.04 LTS, cannot install MongoDB on it.
Code:

[Assistant]
Text:Hi folks! Ubuntu 22.04 has been out for almost 3 months now, when will we be able to install the official version of mongo without all sorts of hacks and tweaks?
Code:

[Assistant]
Text:I got mongodb 5.0.9 installed on ubuntu 22.05… but boy… it was a hassle.First you have to remove the libssl1.1 dep from:My bash script (that’s added below) will open the ‘nano’ editor and offer you to edit the control file specifying the deps. Your are looking for a line like this (starting with “Depends” and containing a reference to “libssl1.1”):Remove the reference to libssl1.1 and save & quit. It should look like this:The script will automagically repackage the files and generate you a new package with ‘-newpackage.deb’ attached to its name:Now put them in a folder and install them manually with dpkg:After that run:Hint: You don’t need ‘mongodb-mongosh’ from the deps as it’s being replaced by ‘mongodb-mongosh-shared-openssl3’.Afterwards I couldn’t start the mongod service:Which was because of a missing user (after looking at ‘/etc/systemd/system/mongod.service’), so I added it:Edit, try, fail, repeat:Missing libcrypto from ssl 1.1…I didn’t have the 3.0 on the system, fix that:Now search for the file:link it:And we got the same error for ssl1.1…Search, link, start…And error (obviously - it’s 3.0, not 1.1…):But didn’t I see a snap with 1.1 libs on the system when running the find commands? - Sure did!Let’s remove the previous link and they those…SUCCESS:Script:
Code:
mongodb-org-mongos_5.0.9_amd64.deb

mongodb-org-server_5.0.9_amd64.deb

mongodb-org-shell_5.0.9_amd64.deb

Depends: libc6 (>= 2.29), libcurl4 (>= 7.16.2), libgcc-s1 (>= 4.2), liblzma5 (>= 5.1.1alpha+20110809), libssl1.1 (>= 1.1.1)

Depends: libc6 (>= 2.29), libcurl4 (>= 7.16.2), libgcc-s1 (>= 4.2), liblzma5 (>= 5.1.1alpha+20110809)

mongodb-org-mongos_5.0.9_amd64.deb-newpackage.deb

mongodb-org-server_5.0.9_amd64.deb-newpackage.deb

mongodb-org-shell_5.0.9_amd64.deb-newpackage.deb

sudo dpkg -i *.deb

sudo apt install --no-install-recommends mongodb-org mongodb-org-database mongodb-org-tools mongodb-mongosh-shared-openssl3

Jun 11 18:14:11 systemd[1]: Started MongoDB Database Server.

Jun 11 18:14:11 systemd[48437]: mongod.service: Failed to determine user credentials: No such process

Jun 11 18:14:11 systemd[48437]: mongod.service: Failed at step USER spawning /usr/bin/mongod: No such process

Jun 11 18:14:11 systemd[1]: mongod.service: Main process exited, code=exited, status=217/USER

Jun 11 18:14:11 systemd[1]: mongod.service: Failed with result 'exit-code'.

sudo adduser mongodb

Jun 11 18:15:53 systemd[1]: Started MongoDB Database Server.

Jun 11 18:15:53 mongod[48504]: /usr/bin/mongod: error while loading shared libraries: libcrypto.so.1.1: cannot open shared object file: No such file or directory

Jun 11 18:15:53 systemd[1]: mongod.service: Main process exited, code=exited, status=127/n/a

Jun 11 18:15:53 systemd[1]: mongod.service: Failed with result 'exit-code'.

sudo apt-get install libssl-dev

sudo find / -type f -name libcrypto.so*

sudo ln -s /usr/lib/x86_64-linux-gnu/libcrypto.so.3 /usr/lib/x86_64-linux-gnu/libcrypto.so.3 /usr/lib/x86_64-linux-gnu/libcrypto.so.1.1

Jun 11 18:23:59 mongod[48822]: /usr/bin/mongod: error while loading shared libraries: libssl.so.1.1: cannot open shared object file: No such file or directory

sudo find / -type f -name libssl.so.*

sudo ln -s /usr/lib/x86_64-linux-gnu/libssl.so.3 /usr/lib/x86_64-linux-gnu/libssl.so.1.1

Jun 11 18:26:29 systemd[1]: Started MongoDB Database Server.

Jun 11 18:26:29 mongod[48845]: /usr/bin/mongod: /lib/x86_64-linux-gnu/libcrypto.so.1.1: version `OPENSSL_1_1_0' not found (required by /usr/bin/mongod)

Jun 11 18:26:29 mongod[48845]: /usr/bin/mongod: /lib/x86_64-linux-gnu/libssl.so.1.1: version `OPENSSL_1_1_0' not found (required by /usr/bin/mongod)

Jun 11 18:26:29 mongod[48845]: /usr/bin/mongod: /lib/x86_64-linux-gnu/libssl.so.1.1: version `OPENSSL_1_1_1' not found (required by /usr/bin/mongod)

$ sudo find / -type f -name libcrypto.so*

/usr/lib/x86_64-linux-gnu/libcrypto.so.3

/snap/core20/1518/usr/lib/x86_64-linux-gnu/libcrypto.so.1.1

$ sudo find / -type f -name libssl.so.*

/usr/lib/x86_64-linux-gnu/libssl.so.3

/snap/core20/1518/usr/lib/x86_64-linux-gnu/libssl.so.1.1

$ sudo rm /usr/lib/x86_64-linux-gnu/libcrypto.so.1.1 /usr/lib/x86_64-linux-gnu/libssl.so.1.1

$ sudo ln -s /snap/core20/1518/usr/lib/x86_64-linux-gnu/libssl.so.1.1 /usr/lib/x86_64-linux-gnu/libssl.so.1.1

$ sudo ln -s /snap/core20/1518/usr/lib/x86_64-linux-gnu/libcrypto.so.1.1 /usr/lib/x86_64-linux-gnu/libcrypto.so.1.1

$ sudo service mongod start && sudo service mongod status

● mongod.service - MongoDB Database Server

Loaded: loaded (/lib/systemd/system/mongod.service; disabled; vendor preset: enabled)

Active: active (running) since Sat 2022-06-11 18:32:20 CEST; 49ms ago

Docs: https://docs.mongodb.org/manual

Main PID: 48894 (mongod)

Memory: 760.0K

CPU: 16ms

CGroup: /system.slice/mongod.service

└─48894 /usr/bin/mongod --config /etc/mongod.conf

Jun 11 18:32:20 systemd[1]: Started MongoDB Database Server.
#!/bin/bash
# name: debedit.sh
# author: showp1984
# description: unpacks, edits control file and repacks deb-files with gz or xz compression
# prerequisites: xz-utils && nano
# No guarantees. Use at your own peril.

unset DECOMPXZ
unset DECOMPGZ
FILES="{post,pre}{inst,rm} conffiles md5sums control"

echo "Uncompressing deb..."
ar x $*

FILEXZ="control.tar.xz"
if [ -f "$FILEXZ" ]; then
    DECOMPXZ=1
    echo "Found: $FILEXZ | using XZ decomp..."
    tar --xz -xvf $FILEXZ
fi

FILEGZ="control.tar.gz"
if [ -f "$FILEGZ" ]; then
    DECOMPGZ=1
    echo "$FILEGZ exists."
    tar xzf $FILEGZ
fi

nano control

if [[ "$DECOMPXZ" == 1 ]]; then
    echo "Repacking $FILEXZ..."
    tar --ignore-failed-read -cvJf $FILEXZ $FILES

    echo "Repacking deb with xz files..."
    ar rcs "${*}-newpackage.deb" debian-binary $FILEXZ data.tar.xz
fi

if [[ "$DECOMPGZ" == 1 ]]; then
    echo "Repacking $FILEGZ..."
    tar --ignore-failed-read -cvzf $FILEGZ $FILES

    echo "Repacking deb with gz files..."
    ar rcs "${*}-newpackage.deb" debian-binary $FILEGZ data.tar.gz
fi

echo "Cleanup..."
rm -r control md5sums debian-binary control.tar.xz data.tar.xz control.tar.gz data.tar.gz postrm preinst prerm conffiles postinst

echo "Done!"


[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 use and format the TIMESTAMP in javascript? and tags: ['crud']

[User]
Text:I’m trying to work with the TIMESTAMP… I’m posting here because I can’t find ANY documentation or examples online or this site. If anybody knows any documentation that would be great!I’m using MongoDB is a basic CMS, for like blog posts. I’m saving created and edited TIMESTAMPS for each post. I have some mongoDB web hook functions that expose these posts to an API, making a headless CMS. The CMS works great, but those timestamps look like:Questions:I want to both display these in useful way in the blog post headers and order by them. What is the best way to format this? How do I do it? I think I’d prefer formatting api side, but I’m open to whatever.I know the ObjectId contains the created date somehow, is it more standard to use that somehow?I have triggers that format the blog posts… how do I automatically stamp the edited?I’m not super opinionated on this, what’s the easiest standard way to work with and format TIMESTAMPs with mongodb?Thanks for any help!General question: I always find MongoDB documentation and community very frustrating. Just trying to do basic thing, like format a timestamp, on other platforms I can find examples and documentation in seconds. Why is it so difficult with MongoDB? What am I doing wrong?Is there a Discord for MongoDB?
Code:creatededited  "created": {
    "$timestamp": {
      "t": 1631414145,
      "i": 5
    }
  },
  "edited": {
    "$timestamp": {
      "t": 1631414145,
      "i": 6
    }
  },
edited

[Assistant]
Text:I’m using MongoDB is a basic CMS, for like blog posts. I’m saving created and edited TIMESTAMPS for each post.I suggest save the created and edited time fields as Date data type (instead of Timestamp type).For example,
Code:creatededitedcreatededitedTimestampvar createdDt = new Date()
db.posts.insertOne({ title: "Working with dates", created: createdDt })
db.posts.findOne()
// returns
{
        "_id" : ObjectId("619474dd9043453a52147dd7"),
        "title" : "Working with dates",
        "created" : ISODate("2021-11-17T03:19:56.186Z")
}

[User]
Text:Thanks!Date() itself serialized as a similar useless object to TIMESTAMP. But storing this post.edited = new Date().toJSON(); creates that more meaningful iso date strong… with presumably I can work with on the frontend.I think this approach will work for me for now… is this standard?
Code:post.edited = new Date().toJSON();

[Assistant]
Text:… is this standard?I think it is not. MongoDB data allows storing date as a date type. It is efficient storage, can be converted to any other forms (e.g., to string), has all the date/time related information, can be used for searching and sorting (compare with other dates), extract and use the different date fields (day, month, year, hour, min, sec, etc.) from it, perform date arithmetic, etc. All these operations can be applied using various query or aggregation operators (see Date Expression Operators).
Code:date


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

[System] The following conversation has title: com.mongodb.MongoNodeIsRecoveringException: Command failed with error 11600 (InterruptedAtShutdown) and tags: ['sharding']

[User]
Text:we have a 6 Shards Cluster with 3 routers and 1 config replica set, we started getting below error when connecting from Routers, couldnt find any specific issue related to the cluster, i can see cluster available up and running, and issue seems intermittentcom.mongodb.MongoNodeIsRecoveringException: Command failed with error 11600 (InterruptedAtShutdown): ‘interrupted at shutdown’ on server XXX:XXX. The full response is {"ok": 0.0, “errmsg”: “interrupted at shutdown”, “code”: 11600, “codeName”: “InterruptedAtShutdown”, “operationTime”: {"$timestamp": {"t": 88608, “i”: 2}}, “$clusterTime”: {"clusterTime": {"$timestamp": {"t": 88608, “i”: 2}}, “signature”: {"hash": {"$binary": {"base64": “XXXXXXXXXXXX”, “subType”: “00”}}, “keyId”: XXXXXXXXXXXXXX}}} at com.mongodb.internal.connection.ProtocolHelper.createSpecialException(ProtocolHelper.java:242) ~[mongodb-driver-core-4.1.1.jar:na] at com.mongodb.internal.connection.ProtocolHelper.getCommandFailureException(ProtocolHelper.java:171) ~[mongodb-driver-core-4.1.1.jar:na] at com.mongodb.internal.connection.InternalStreamConnection.receiveCommandMessageResponse(InternalStreamConnection.java:359) ~[mongodb-driver-core-4.1.1.jar:na] at com.mongodb.internal.connection.InternalStreamConnection.receive(InternalStreamConnection.java:316) ~[mongodb-driver-core-4.1.1.jar:na] at com.mongodb.internal.connection.DefaultServerMonitor$ServerMonitorRunnable.lookupServerDescription(DefaultServerMonitor.java:215) ~[mongodb-driver-core-4.1.1.jar:na] at com.mongodb.internal.connection.DefaultServerMonitor$ServerMonitorRunnable.run(DefaultServerMonitor.java:144) ~[mongodb-driver-core-4.1.1.jar:na] at java.lang.Thread.run(Thread.java:748) [na:1.8.0_191]
Code:

[Assistant]
Text:Hi @Bhaskar_Avisha
First of all, welcome to MongoDB Community Forum… Command failed with error 11600 (InterruptedAtShutdown):I believe error 11600 means that the client is trying to do an operation on a server that is shutting down.So, if you provide the driver with a connection URI that specifies a replica set, the driver should reconnect to the new primary as soon as it’s available. See Connection String URI Format, specifically the replica set option section.I hope it works for you.
Let us know if it or still persists.In case of any doubts please feel free to reach out.Regards,
Kushagra
Code:

[User]
Text:Thanks @Kushagra_KesavI am getting this error , when application is connecting through mongos ,  this is not a direct connection to replica set.
Code:

[Assistant]
Text:Hi @Bhaskar_Avisha,As far as I can tell, the com.mongodb.MongoNodeIsRecoveringException is a possible error that happens when you’re connected to a replica set. From the linked page:An exception indicating that the server is a member of a replica set but is in recovery mode, and therefore refused to execute the operation. This can happen when a server is starting up and trying to join the replica set.However I don’t think there’s enough information here to determine what’s going on. Could you post more details:Best regards,
Kevin
Code:mongosmongo

[Assistant]
Text:Hi @Bhaskar_Avisha, have you got your issue resolved?
We’re facing a similar problem, our client application keeps loosing the connection to the Atlas cluster and since we are using tailable cursors, our app has to restart upon each interruption which is highly annoying.
The client connects to the cluster via ‘mongodb+srv://’ URL
Code: Jan 10 23:20:10 ip-***.eu-west-1.compute.internal  [cluster-ClusterId{value='61dc9f7a153a5d03282359a1', description='null'}-demo-shard-00-01.l76nh.mongodb.net:27017] WARN  c.g.r.c.config.MongoDbConfiguration: MongoDB serverHeartbeatFailed: ServerHeartbeatFailedEvent{connectionId=connectionId{localValue:12, serverValue:269}, elapsedTimeNanos=950823445, awaited=true, throwable=com.mongodb.MongoNodeIsRecoveringException: Command failed with error 11600 (InterruptedAtShutdown): 'interrupted at shutdown' on server ***.l76nh.mongodb.net:27017. The full response is {"operationTime": {"$timestamp": {"t": 1641853208, "i": 11}}, "ok": 0.0, "errmsg": "interrupted at shutdown", "code": 11600, "codeName": "InterruptedAtShutdown", "$clusterTime": {"clusterTime": {"$timestamp": {"t": 1641853208, "i": 15}}, "signature": {"hash": {"$binary": {"base64": "5cTlPKELM4icjdNscfA1g85B75s=", "subType": "00"}}, "keyId": 7006031879656701953}}}} com.mongodb.event.ServerHeartbeatFailedEvent@583a7488
Jan 10 23:20:10 ip-***.eu-west-1.compute.internal  org.springframework.data.mongodb.UncategorizedMongoDbException: Query failed with error code 11600 and error message 'interrupted at shutdown' on server demo-shard-00-01.l76nh.mongodb.net:27017; nested exception is com.mongodb.MongoQueryException: Query failed with error code 11600 and error message 'interrupted at shutdown' on server ***.l76nh.mongodb.net:27017
 	at org.springframework.data.mongodb.core.MongoExceptionTranslator.translateExceptionIfPossible(MongoExceptionTranslator.java:140)
 	at org.springframework.data.mongodb.core.ReactiveMongoTemplate.potentiallyConvertRuntimeException(ReactiveMongoTemplate.java:2814)
 	at org.springframework.data.mongodb.core.ReactiveMongoTemplate.lambda$translateException$90(ReactiveMongoTemplate.java:2797)
 	at reactor.core.publisher.Flux.lambda$onErrorMap$28(Flux.java:6910)
 	at reactor.core.publisher.FluxOnErrorResume$ResumeSubscriber.onError(FluxOnErrorResume.java:94)

[Assistant]
Text:Hi, everyone!
We also encountered this problem while upgrading our MongoDB shard cluster from 4.0.12 to 4.2.17.
During the upgrade we were observing this kind of error messages in our logs(I edited out the collection names, filters, signature, and router names.)The upgrade process was as follows:As we observed, the aforementioned errors were showing up right after stopping the process. And also we saw the errors while connecting with ReadPreference = Primary and 				ReadPreference = SecondaryPreferred.To answer @kevinadi questions:What we want to know is how to upgrade a MongoDB shard cluster more flawlessly. Any advice is really appreciated.
Code:Code: 11600;
CodeName: InterruptedAtShutdown;
Command: { "getMore" : NumberLong("9001353061637322596"), "collection" : "some.collection" };
ErrorMessage: interrupted at shutdown;
Result: { "ok" : 0.0, "errmsg" : "interrupted at shutdown", "code" : 11600, "codeName" : "InterruptedAtShutdown" };
ConnectionId: { ServerId : { ClusterId : 1, EndPoint : "Unspecified/some.router.name:27017" }, LocalValue : 290 };
ErrorLabels: System.Collections.Generic.List`1[System.String]

MongoDB.Driver.MongoNodeIsRecoveringException: Server returned node is recovering error (code = 11600, codeName = "InterruptedAtShutdown").
   at MongoDB.Driver.Core.WireProtocol.CommandUsingCommandMessageWireProtocol`1.ProcessResponse(ConnectionId connectionId, CommandMessage responseMessage)
   at MongoDB.Driver.Core.WireProtocol.CommandUsingCommandMessageWireProtocol`1.Execute(IConnection connection, CancellationToken cancellationToken)
   at MongoDB.Driver.Core.WireProtocol.CommandWireProtocol`1.Execute(IConnection connection, CancellationToken cancellationToken)
   at MongoDB.Driver.Core.Servers.Server.ServerChannel.ExecuteProtocol[TResult](IWireProtocol`1 protocol, ICoreSession session, CancellationToken cancellationToken)
   at MongoDB.Driver.Core.Servers.Server.ServerChannel.Command[TResult](ICoreSession session, ReadPreference readPreference, DatabaseNamespace databaseNamespace, BsonDocument command, IEnumerable`1 commandPayloads, IElementNameValidator commandValidator, BsonDocument additionalOptions, Action`1 postWriteAction, CommandResponseHandling responseHandling, IBsonSerializer`1 resultSerializer, MessageEncoderSettings messageEncoderSettings, CancellationToken cancellationToken)
   at MongoDB.Driver.Core.Operations.AsyncCursor`1.ExecuteGetMoreCommand(IChannelHandle channel, CancellationToken cancellationToken)
   at MongoDB.Driver.Core.Operations.AsyncCursor`1.GetNextBatch(CancellationToken cancellationToken)
   at MongoDB.Driver.Core.Operations.AsyncCursor`1.MoveNext(CancellationToken cancellationToken)
   at MongoDB.Driver.IAsyncCursorExtensions.ToList[TDocument](IAsyncCursor`1 source, CancellationToken cancellationToken)
   at MongoDB.Driver.IAsyncCursorSourceExtensions.ToList[TDocument](IAsyncCursorSource`1 source, CancellationToken cancellationToken)
Code: 11600;
CodeName: InterruptedAtShutdown;
Command: { "find" : "some.collection", "filter" : {somefilter} };
ErrorMessage: Encountered non-retryable error during query :: caused by :: interrupted at shutdown;
Result: { "ok" : 0.0, "errmsg" : "Encountered non-retryable error during query :: caused by :: interrupted at shutdown", "code" : 11600, "codeName" : "InterruptedAtShutdown", "operationTime" : Timestamp(1642587846, 583), "$clusterTime" : { "clusterTime" : Timestamp(1642587850, 1385), "signature" : { "some signature"  } } };
ConnectionId: { ServerId : { ClusterId : 2, EndPoint : "Unspecified/some.router.name:27017" }, LocalValue : 4228 };
ErrorLabels: System.Collections.Generic.List`1[System.String]

MongoDB.Driver.MongoNodeIsRecoveringException: Server returned node is recovering error (code = 11600, codeName = "InterruptedAtShutdown").
   at MongoDB.Driver.Core.Operations.RetryableReadOperationExecutor.ExecuteAsync[TResult](IRetryableReadOperation`1 operation, RetryableReadContext context, CancellationToken cancellationToken)
   at MongoDB.Driver.Core.Operations.ReadCommandOperation`1.ExecuteAsync(RetryableReadContext context, CancellationToken cancellationToken)
   at MongoDB.Driver.Core.Operations.FindCommandOperation`1.ExecuteAsync(RetryableReadContext context, CancellationToken cancellationToken)
   at MongoDB.Driver.Core.Operations.FindOperation`1.ExecuteAsync(RetryableReadContext context, CancellationToken cancellationToken)
   at MongoDB.Driver.Core.Operations.FindOperation`1.ExecuteAsync(IReadBinding binding, CancellationToken cancellationToken)
   at MongoDB.Driver.OperationExecutor.ExecuteReadOperationAsync[TResult](IReadBinding binding, IReadOperation`1 operation, CancellationToken cancellationToken)
   at MongoDB.Driver.MongoCollectionImpl`1.ExecuteReadOperationAsync[TResult](IClientSessionHandle session, IReadOperation`1 operation, ReadPreference readPreference, CancellationToken cancellationToken)
   at MongoDB.Driver.MongoCollectionImpl`1.UsingImplicitSessionAsync[TResult](Func`2 funcAsync, CancellationToken cancellationToken)
systemctl stop mongodsystemctl stop mongosmongodmongosReadPreference = Primary				ReadPreference = SecondaryPreferred4.0.122.11.4			var settings = new MongoClientSettings
			{
				Servers = "{router names}",
				ConnectionMode = ConnectionMode.Automatic,
				MaxConnectionIdleTime = TimeSpan.FromMinutes(10),
				MaxConnectionLifeTime = TimeSpan.FromMinutes(30),
				MaxConnectionPoolSize = 100,
				MinConnectionPoolSize = 1,
				ReadPreference = ReadPreference.Primary, // and could be SecondaryPreferred
				SocketTimeout = TimeSpan.Zero,
				WaitQueueTimeout = TimeSpan.FromMinutes(2),
				WriteConcern = WriteConcern.W1,
				ConnectTimeout = TimeSpan.FromSeconds(15),
				ReadConcern = ReadConcern.Default,
				ServerSelectionTimeout = TimeSpan.FromSeconds(15),
			};

mongo

[Assistant]
Text:We’re running into this same issue while doing a rolling upgrade from 4.0 → 4.2 .
All clients are running java.Any updates or solutions available?
Thanks,
Tom
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: MongoDB.Driver.MongoConnectionException: An exception occurred while sending a message to the server and tags: []

[User]
Text:I got below exception while try to update data in mongodb. Please help me to fix this issue.When I look in my logs I see lot of error messages just like the one below where the driver is getting a socket error when connecting to mongo. The site is still up and this error doesn’t happen on every request, nor does it happen on one operation that should take longer.The version I have used C# driver : “2.10.2” and Azure Cosmos version :3.6".Code that causes issue,
Code:MongoDB.Driver.MongoConnectionException: An exception occurred while sending a message to the server. ---> System.IO.IOException: Unable to write data to 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.Send(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags)
   at System.Net.Sockets.NetworkStream.Write(Byte[] buffer, Int32 offset, Int32 size)
   --- End of inner exception stack trace ---
   at System.Net.Sockets.NetworkStream.Write(Byte[] buffer, Int32 offset, Int32 size)
   at System.Net.Security._SslStream.StartWriting(Byte[] buffer, Int32 offset, Int32 count, AsyncProtocolRequest asyncRequest)
   at System.Net.Security._SslStream.ProcessWrite(Byte[] buffer, Int32 offset, Int32 count, AsyncProtocolRequest asyncRequest)
   at System.Net.Security.SslStream.Write(Byte[] buffer, Int32 offset, Int32 count)
   at MongoDB.Driver.Core.Misc.StreamExtensionMethods.WriteBytes(Stream stream, IByteBuffer buffer, Int32 offset, Int32 count, CancellationToken cancellationToken)
   at MongoDB.Driver.Core.Connections.BinaryConnection.SendBuffer(IByteBuffer buffer, CancellationToken cancellationToken)
   --- End of inner exception stack trace ---
   at MongoDB.Driver.Core.Connections.BinaryConnection.SendBuffer(IByteBuffer buffer, CancellationToken cancellationToken)
   at MongoDB.Driver.Core.Connections.BinaryConnection.SendMessages(IEnumerable`1 messages, MessageEncoderSettings messageEncoderSettings, CancellationToken cancellationToken)
   at MongoDB.Driver.Core.ConnectionPools.ExclusiveConnectionPool.AcquiredConnection.SendMessages(IEnumerable`1 messages, MessageEncoderSettings messageEncoderSettings, CancellationToken cancellationToken)
   at MongoDB.Driver.Core.Connections.ConnectionExtensions.SendMessage(IConnection connection, RequestMessage message, MessageEncoderSettings messageEncoderSettings, CancellationToken cancellationToken)
   at MongoDB.Driver.Core.WireProtocol.CommandUsingCommandMessageWireProtocol`1.Execute(IConnection connection, CancellationToken cancellationToken)
   at MongoDB.Driver.Core.WireProtocol.CommandWireProtocol`1.Execute(IConnection connection, CancellationToken cancellationToken)
   at MongoDB.Driver.Core.Servers.Server.ServerChannel.ExecuteProtocol[TResult](IWireProtocol`1 protocol, ICoreSession session, CancellationToken cancellationToken)
   at MongoDB.Driver.Core.Servers.Server.ServerChannel.Command[TResult](ICoreSession session, ReadPreference readPreference, DatabaseNamespace databaseNamespace, BsonDocument command, IEnumerable`1 commandPayloads, IElementNameValidator commandValidator, BsonDocument additionalOptions, Action`1 postWriteAction, CommandResponseHandling responseHandling, IBsonSerializer`1 resultSerializer, MessageEncoderSettings messageEncoderSettings, CancellationToken cancellationToken)
   at MongoDB.Driver.Core.Operations.RetryableWriteCommandOperationBase.ExecuteAttempt(RetryableWriteContext context, Int32 attempt, Nullable`1 transactionNumber, CancellationToken cancellationToken)
   at MongoDB.Driver.Core.Operations.RetryableWriteOperationExecutor.Execute[TResult](IRetryableWriteOperation`1 operation, RetryableWriteContext context, CancellationToken cancellationToken)
   at MongoDB.Driver.Core.Operations.BulkUnmixedWriteOperationBase`1.ExecuteBatch(RetryableWriteContext context, Batch batch, CancellationToken cancellationToken)
   at MongoDB.Driver.Core.Operations.BulkUnmixedWriteOperationBase`1.ExecuteBatches(RetryableWriteContext context, CancellationToken cancellationToken)
   at MongoDB.Driver.Core.Operations.BulkUnmixedWriteOperationBase`1.Execute(RetryableWriteContext context, CancellationToken cancellationToken)
   at MongoDB.Driver.Core.Operations.BulkMixedWriteOperation.ExecuteBatch(RetryableWriteContext context, Batch batch, CancellationToken cancellationToken)
   at MongoDB.Driver.Core.Operations.BulkMixedWriteOperation.Execute(IWriteBinding binding, CancellationToken cancellationToken)
   at MongoDB.Driver.OperationExecutor.ExecuteWriteOperation[TResult](IWriteBinding binding, IWriteOperation`1 operation, CancellationToken cancellationToken)
   at MongoDB.Driver.MongoCollectionImpl`1.ExecuteWriteOperation[TResult](IClientSessionHandle session, IWriteOperation`1 operation, CancellationToken cancellationToken)
   at MongoDB.Driver.MongoCollectionImpl`1.BulkWrite(IClientSessionHandle session, IEnumerable`1 requests, BulkWriteOptions options, CancellationToken cancellationToken)
   at MongoDB.Driver.MongoCollectionImpl`1.<>c__DisplayClass23_0.<BulkWrite>b__0(IClientSessionHandle session)
   at MongoDB.Driver.MongoCollectionImpl`1.UsingImplicitSession[TResult](Func`2 func, CancellationToken cancellationToken)
   at MongoDB.Driver.MongoCollectionImpl`1.BulkWrite(IEnumerable`1 requests, BulkWriteOptions options, CancellationToken cancellationToken)
   at MongoDB.Driver.MongoCollectionBase`1.<>c__DisplayClass92_0.<UpdateMany>b__0(IEnumerable`1 requests, BulkWriteOptions bulkWriteOptions)
   at MongoDB.Driver.MongoCollectionBase`1.UpdateMany(FilterDefinition`1 filter, UpdateDefinition`1 update, UpdateOptions options, Func`3 bulkWrite)
   at MongoDB.Driver.MongoCollectionBase`1.UpdateMany(FilterDefinition`1 filter, UpdateDefinition`1 update, UpdateOptions options, CancellationToken cancellationToken)
   at Sensiple.Tryvium.Data.MongoDB.CommonConnector.Update(String schemaName, String dataFilter, String data, String logSource)
var _collection = Db.GetCollection<BsonDocument>(schemaName);

BsonDocument bsonDocument = new BsonDocument(BsonSerializer.Deserialize<BsonDocument>(dataFilter));

var updatedResult = _collection.UpdateMany(bsonDocument, BsonDocument.Parse("{$set: " + BsonSerializer.Deserialize<BsonDocument>(data) + "}"));

[Assistant]
Text:Hi,The version I have used  C# driver : “2.10.2” and Azure Cosmos version :3.6".It appears that you are trying to connect to Azure Cosmos DB using the official MongoDB dotnet driver. Is this correct?If yes, then unfortunately this configuration is not supported since Cosmos DB is a Microsoft product that provides MongoDB compatibility, and thus it may time to time see some incompatibilities with official MongoDB drivers, which are designed for use with the official MongoDB server.Could you try the code on an official MongoDB server (e.g. a free MongoDB Atlas shared instance for testing purposes) and see if the error persists? If not, then you may want to contact Microsoft support regarding this issue.Best regards,
Kevin
Code:

[Assistant]
Text:I’ve had the exact same issue (using exact same driver version 2.10.2), and it started exactly after I’ve upgraded from Cosmos 3.2 to 3.6 (also happens with 4.0) and the issue was solved by forcing TLS 1.2var settings = MongoClientSettings.FromConnectionString(connectionString);
settings.SslSettings = new SslSettings()
{
EnabledSslProtocols = System.Security.Authentication.SslProtocols.Tls12
};
return new MongoClient(settings);
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: Ubuntu 22.04 and mssing libcrypto.so.1.1 and tags: []

[User]
Text:I’m trying to use mongo shell on Ubuntu 22.04, but libcrypto.so.1.1 isn’t available.That library doesn’t exist in any package for Jammy:https://packages.ubuntu.com/search?suite=jammy&arch=any&mode=exactfilename&searchon=contents&keywords=libcrypto.so.1.1Is there a solution for this?
Code:libcrypto.so.1.1mongodb-shell-linux-x86_64-ubuntu2004-5.0.9/mongodb-linux-x86_64-ubuntu2004-5.0.9$ ./bin/mongo 192.168.1.20:27017
./bin/mongo: error while loading shared libraries: libcrypto.so.1.1: cannot open shared object file: No such file or directory

[Assistant]
Text:mongosh is available as a PPA for Ubuntu 20.04 (Focal) and Ubuntu 18.04 (Bionic).Wait for a package that supports 22.04.Run a container in the meantime ?
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: Using MongoDB Atlas on Lambda throws Could not connect to any servers in MongoDB Atlas cluster error and tags: ['node-js', 'mongoose-odm', 'serverless']

[User]
Text:I am using node lambda which is a api server that accepts request from API gateway.  The lambda connects to mongo db atlas to pull data from the db and then returns it in the response.  For the most part it works fine with no issues but randomly it runs into mongo atlas connection errors:My mongo DB atlas instance allows ip addresses from everywhere: 0.0.0.0.This is how I am making my mongo connection:I am also using mongoose version 5.12.8
Code:    {
    "errorType": "Runtime.UnhandledPromiseRejection",
    "errorMessage": "MongooseServerSelectionError: Could not connect to any servers in your MongoDB Atlas cluster. One common reason is that you're trying to access the database from an IP that isn't whitelisted. Make sure your current IP address is on your Atlas cluster's IP whitelist: https://docs.atlas.mongodb.com/security-whitelist/",
    "reason": {
        "errorType": "MongooseServerSelectionError",
        "errorMessage": "Could not connect to any servers in your MongoDB Atlas cluster. One common reason is that you're trying to access the database from an IP that isn't whitelisted. Make sure your current IP address is on your Atlas cluster's IP whitelist: https://docs.atlas.mongodb.com/security-whitelist/",
        "message": "Could not connect to any servers in your MongoDB Atlas cluster. One common reason is that you're trying to access the database from an IP that isn't whitelisted. Make sure your current IP address is on your Atlas cluster's IP whitelist: https://docs.atlas.mongodb.com/security-whitelist/",
        "reason": {
            "type": "ReplicaSetNoPrimary",
            "setName": null,
            "maxSetVersion": null,
            "maxElectionId": null,
            "servers": {},
            "stale": false,
            "compatible": true,
            "compatibilityError": null,
            "logicalSessionTimeoutMinutes": null,
            "heartbeatFrequencyMS": 10000,
            "localThresholdMS": 15,
            "commonWireVersion": null
        },
        "stack": [
            "MongooseServerSelectionError: Could not connect to any servers in your MongoDB Atlas cluster. One common reason is that you're trying to access the database from an IP that isn't whitelisted. Make sure your current IP address is on your Atlas cluster's IP whitelist: https://docs.atlas.mongodb.com/security-whitelist/",
            "    at NativeConnection.Connection.openUri (/var/task/node_modules/mongoose/lib/connection.js:846:32)",
            "    at /var/task/node_modules/mongoose/lib/index.js:351:10",
            "    at /var/task/node_modules/mongoose/lib/helpers/promiseOrCallback.js:31:5",
            "    at new Promise (<anonymous>)",
            "    at promiseOrCallback (/var/task/node_modules/mongoose/lib/helpers/promiseOrCallback.js:30:10)",
            "    at Mongoose._promiseOrCallback (/var/task/node_modules/mongoose/lib/index.js:1149:10)",
            "    at Mongoose.connect (/var/task/node_modules/mongoose/lib/index.js:350:20)",
            "    at Object.<anonymous> (/var/task/build/app.js:172:40)",
            "    at Module._compile (internal/modules/cjs/loader.js:999:30)",
            "    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)",
            "    at Module.load (internal/modules/cjs/loader.js:863:32)",
            "    at Function.Module._load (internal/modules/cjs/loader.js:708:14)",
            "    at Module.require (internal/modules/cjs/loader.js:887:19)",
            "    at require (internal/modules/cjs/helpers.js:74:18)",
            "    at _tryRequire (/var/runtime/UserFunction.js:75:12)",
            "    at _loadUserApp (/var/runtime/UserFunction.js:95:12)"
        ]
    },
    "promise": {},
    "stack": [
        "Runtime.UnhandledPromiseRejection: MongooseServerSelectionError: Could not connect to any servers in your MongoDB Atlas cluster. One common reason is that you're trying to access the database from an IP that isn't whitelisted. Make sure your current IP address is on your Atlas cluster's IP whitelist: https://docs.atlas.mongodb.com/security-whitelist/",
        "    at process.<anonymous> (/var/runtime/index.js:35:15)",
        "    at process.emit (events.js:314:20)",
        "    at process.EventEmitter.emit (domain.js:483:12)",
        "    at processPromiseRejections (internal/process/promises.js:209:33)",
        "    at processTicksAndRejections (internal/process/task_queues.js:98:32)"
    ]
}
import express from "express";
import serverless from "serverless-http";
import mongoose, { Error } from "mongoose";
import { APIGatewayProxyHandler } from 'aws-lambda';
import { AppSettings } from "./constants/constants";

class App {

    public app: express.Application;
    public mongoUrl: string = AppSettings.MONGODBURL;

    constructor() {
        this.setupDBConn();
    }
    async setupDBConn() {
        this.app = express();
    }

    private async mongoSetup() {
        await mongoClient;
        console.log('MONGO connection successfully made...');
    }
}
const mongoClient = mongoose.connect(AppSettings.MONGODBURL, { useNewUrlParser: true, useUnifiedTopology: true, useCreateIndex: true, useFindAndModify: false });
export const handler: APIGatewayProxyHandler = serverless(new App().app);

[Assistant]
Text:Hi @Shawn_Varughese and welcome in the MongoDB Community  !Are you creating a new connection (==mongoClient) for each Lambda or your MongoDB Connections are shared across multiple (all) lambdas?I give you a little hint, “yes” is a very bad answer  !Check out this doc where they explain how to set up the connection correctly:Using a private endpoint would also be a plus (instead of 0.0.0.0/0).Cheers,
Maxime.
Code:

[User]
Text:Thanks for this and this is helpful I did go through this and we do have the connection outside the lambda function and the connection is shared  in the code we have the mongoClient outside the App class and the serverless function just waits for the mongo connection and reuses it.  Unfortunately we are still seeing this connection issue.Any other ideas on why we might be seeing this?
Code:

[Assistant]
Text:I don’t understand why you would get this error if the connection was already established and functional and if your cluster is healthy on the other hand. This error message makes me think that the connection is being created at that moment.If it’s really an occasional error, maybe this is happening when you have a maintenance on the cluster? Can you link this to an event in Atlas?
But in theory, it’s supposed to be transparent for the clients, unless something is misconfigured.
Code:

[User]
Text:Interesting I am not sure that could be possible.  I dont see any open alerts in Atlas is that what you were asking for?  To give you more context our platform is microservices based so we have 8 microservices which are all separate lambda functions and each connect to atlas to read/write to the database.You dont see this as a problem right?
Code:

[Assistant]
Text:I dont see any open alerts in Atlas is that what you were asking for?Yes. Then it’s something else.You dont see this as a problem right?No, sounds like I would do exactly the same thing. Given that your connection pool is centralised and reused correctly by all the lambdas, maybe you could increase the size of the pool? If you have many lambdas running in parallel, I guess you need a connection pool large enough to accommodate all the queries.
Code:

[User]
Text:So are you all 8 microservices should share the same connection pool?  How would i be able to do that if they are all separate lambda functionsOr each lambda function shares its own connection pool and just does not create a new connection each invocation?
Code:

[Assistant]
Text:Ado proposed an implementation here based on a cache:Learn how to write serverless functions with AWS Lambda and MongoDBIt’s fine if you use like 8 different pools as long as it’s a small number, it’s OK. What’s not OK is one connection to the cluster per lambda execution. That’s definitely a problem.Your cluster can only support a limited number of connections. For an M10 it’s 1500 per node for example.https://www.mongodb.com/docs/atlas/reference/atlas-limits/.Keep an eye on the monitoring to see if you are getting close to that limit.Cheers,
Maxime.
Code:

[User]
Text:Thanks for this i was able to implementing the caching and it seems like it working well so far! Now after implementing caching i am facing a new error:This doesn’t happen all the time just randomly I assume its because the cached db connection has timed out.  Any advise here?
Code:ERROR	Unhandled Promise Rejection 	{
  "errorType": "Runtime.UnhandledPromiseRejection",
  "errorMessage": "MongoNetworkTimeoutError: connection timed out",
  "reason": {
    "errorType": "MongoNetworkTimeoutError",
    "errorMessage": "connection timed out",
    "name": "MongoNetworkTimeoutError",
    "stack": [
      "MongoNetworkTimeoutError: connection timed out",
      "    at connectionFailureError (/var/task/node_modules/mongodb/lib/core/connection/connect.js:362:14)",
      "    at TLSSocket.<anonymous> (/var/task/node_modules/mongodb/lib/core/connection/connect.js:330:16)",
      "    at Object.onceWrapper (events.js:420:28)",
      "    at TLSSocket.emit (events.js:314:20)",
      "    at TLSSocket.EventEmitter.emit (domain.js:483:12)",
      "    at TLSSocket.Socket._onTimeout (net.js:483:8)",
      "    at listOnTimeout (internal/timers.js:554:17)",
      "    at processTimers (internal/timers.js:497:7)"
    ]
  },
  "promise": {},
  "stack": [
    "Runtime.UnhandledPromiseRejection: MongoNetworkTimeoutError: connection timed out",
    "    at /var/runtime/index.js:35:15",
    "    at /opt/nodejs/node_modules/@lumigo/tracer/dist/tracer/tracer.js:265:37",
    "    at processTicksAndRejections (internal/process/task_queues.js:97:5)"
  ]
}

[User]
Text:@MaBeuLux88 any thoughts on this error i am getting now after implementing the cacheing?
Code:

[Assistant]
Text:Hey @Shawn_Varughese,So sorry for the terrible delay to answer. I had a baby on May 1st so I was a little distracted.To be honest, I have no idea at all. If it’s happening “randomly”, is this happening maybe after your lambda wasn’t triggered for a long time?What timeout have your defined? Did you try to increase them a bit so maybe this gives more opportunity for this connection to land?Search for “timeout” in here and try to increase the relevant one maybe? I assume connectTimeoutMS here, no?Cheers,
Maxime.
Code:connectTimeoutMS

[User]
Text:@MaBeuLux88 ,Not a problem at all congratulations on your baby!!!Yeah I tried changing socketTimeout but that did not seem to help.  Do you think the connectTimeout might be better?  I am stumped on whats causing this.
Code:

[Assistant]
Text:Thanks  !connectTimeout would only apply to the very first connection that is then cached for later use by the lambdas. So I think this isn’t the one you are looking for but… Give it a try?Cheers,
Maxime.
Code:connectTimeout

[Assistant]
Text:We’ve been suffering from the exact same problem - occasional timeouts on connection to Mongo from AWS Lambda. It feels like an event / issue occurring on the MongoDb / Atlas instance - but nothing in the Atlas event log to indicate as such.Our lambda timeout is being hit at 60 seconds - but basically Atlas is just not giving a connection - without error other than via connection timeout.We work in c# and are establishing our MongoClient connections via DI - ie outside of each method function call - just on initialisation.
Code:

[Assistant]
Text:Hi @Stewart_Snow and welcome in the MongoDB Community  !Did you try to add some options to the C# driver connection like increase the timeouts, etc ? Maybe waitQueueTimeoutMS can help?Cheers,
Maxime.
Code:waitQueueTimeoutMS

[Assistant]
Text:https://www.mongodb.com/docs/manual/reference/connection-string/#connection-pool-optionsHey - we can try that - but it feels wrong. In this case the database that we’re connecting to (running in Atlas) is absolutely tiny - barely 50kb of data. At max there is 10 connections open to it. It’s just so small / lightweight that it really shouldn’t be behaving as it is - it makes no sense.I can understand needing big timeouts - some sort of heavily load scenario’s - but we’re dealing with such a low-load scenario it’s strange. Timing out at 60 seconds or so - just to get the connection to the DB seems very strange indeed.We’re having a go at trying a slightly different pattern for the initialization of our mongo connection from our Lambda function to see if that makes any difference.
Code:

[Assistant]
Text:I’m wondering if there is a limit to keep the connection alive if it’s not used for a long time. Please let me know if you find a solution because I don’t have a test environment up to test it at the moment.Also you read that one right?
Code:

[Assistant]
Text:Will do - and yes aware of that doc - cheers!
Code:

[Assistant]
Text:Okay - just following up here. We tweaked our initialisation code, so that we’re 100% inline with mongo / lambda recommendations - but it’s still producing the same issue on occasion.Each time it occurs we get two close errors:Error 1
An unhandled exception has occurred while executing the request.System.TimeoutException: A timeout occurred after 30000ms selecting a server using CompositeServerSelector{ Selectors = ReadPreferenceServerSelector{ ReadPreference = { Mode : Primary } }, LatencyLimitingServerSelector{ AllowedLatencyRange = 00:00:00.0150000 }, OperationsCountServerSelector }. Client view of cluster state is { ClusterId : “1”, ConnectionMode : “ReplicaSet”, Type : “ReplicaSet”, State : “Connected”, Servers : [{ ServerId: “{ ClusterId : 1, EndPoint : “Unspecified/XXXXXX” }”, EndPoint: “Unspecified/XXXXXXX”, ReasonChanged: “Heartbeat”, State: “Connected”, ServerVersion: 5.0.9, TopologyVersion: { “processId” : ObjectId(“62aa3b6c7c78a0c51037b843”), “counter” : NumberLong(4) }, Type: “ReplicaSetSecondary”, Tags: “{ region : US_EAST_1, provider : AWS, nodeType : ELECTABLE, workloadType : OPERATIONAL }”, WireVersionRange: “[0, 13]”, LastHeartbeatTimestamp: “2022-06-27T10:25:32.0295404Z”, LastUpdateTimestamp: “2022-06-27T10:25:32.0295416Z” }, { ServerId: “{ ClusterId : 1, EndPoint : “Unspecified/XXXXX” }”, EndPoint: “Unspecified/XXXXXX”, 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 X.X.X.X. Timeout was 00:00:30. at MongoDB.Driver.Core.Connections.TcpStreamFactory.ConnectAsync(Socket socket, EndPoint endPoint, CancellationToken cancellationToken) at MongoDB.Driver…Error 2
[Error] An unhandled exception has occurred while executing the request.MongoDB.Driver.MongoConnectionException: An exception occurred while opening a connection to the server. —> System.IO.IOException: Unable to read data from the transport connection: Connection reset by peer. —> System.Net.Sockets.SocketException (104): Connection reset by peer   — End of inner exception stack trace —   at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.ThrowException(SocketError error, CancellationToken cancellationToken)   at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.GetResult(Int16 token)   at System.Net.FixedSizeReader.ReadPacketAsync(Stream transport, AsyncProtocolRequest request)   at System.Net.Security.SslStream.InternalEndProcessAuthentication(LazyAsyncResult lazyResult)   at System.Net.Security.SslStream.EndProcessAuthentication(IAsyncResult result)   at System.Net.Security.SslStream.EndAuthenticateAsClient(IAsyncResult asyncResult)   at System.Net.Security.SslStream.<>c.b__64_2(IAsyncResult iar)   at System.Threading.Tasks.TaskFactory1.FromAsyncCoreLogic(IAsyncResult iar, Func2 endFunction, Action1 endAction, Task1 promise, Boolean requiresSynchronization)— End of stack trace from previous location where exception was thrownWe’re using mongo+srv style connection string plus the following options:
retryWrites=true&w=majority…? We’re at a loss - makes no sense. Any suggestions??
Code:1.FromAsyncCoreLogic(IAsyncResult iar, Func1 endAction, Task


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

[System] The following conversation has title: MongoServerSelectionError: connect ECONNREFUSED 127.0.0.1:27017 and tags: ['node-js', 'server', 'storage']

[User]
Text:Hi, could you help me?
I keep getting this error when I launch node app.js.
Mongo shell connects, service MongoDB running (win11), me desperate.This is the code, tested fine on other machines:My config file looks like this, tried all possible combinations of paths and optional
Code:MongoServerSelectionError: connect ECONNREFUSED 127.0.0.1:27017
    at Timeout._onTimeout (/.../node_modules/mongodb/lib/sdam/topology.js:293:38)
    at listOnTimeout (node:internal/timers:557:17)
    at processTimers (node:internal/timers:500:7) {
  reason: TopologyDescription {
    type: 'Unknown',
    servers: Map(1) { '127.0.0.1:27017' => [ServerDescription] },
    stale: false,
    compatible: true,
    heartbeatFrequencyMS: 10000,
    localThresholdMS: 15,
    setName: null,
    maxElectionId: null,
    maxSetVersion: null,
    commonWireVersion: 0,
    logicalSessionTimeoutMinutes: null
  },
  code: undefined,
  [Symbol(errorLabels)]: Set(0) {}
}
const { MongoClient } = require("mongodb");

const uri = "mongodb://127.0.0.1:27017/"
const client = new MongoClient(uri);
async function run() {
  try {
    const database = client.db('sample_mflix');
    const movies = database.collection('movies');
    // Query for a movie that has the title 'Back to the Future'
    const query = { title: 'Back to the Future' };
    const movie = await movies.findOne(query);
    console.log(movie);
  } finally {
    // Ensures that the client will close when you finish/error
    await client.close();
  }
}
run().catch(console.dir);

storage:
  dbPath: C:\data\db
  journal:
    enabled: true
#  engine:
#  wiredTiger:

# where to write logging data.
systemLog:
  destination: file
  logAppend: true
  path:  C:\Program Files\MongoDB\Server\6.0\log\mongod.log

# network interfaces
net:
  port: 27017
  bindIp: 127.0.0.1
  ipv6: true

[Assistant]
Text:Is your service up and running,?
Show snapshot of your Windows service and shell connection you connected successfully
Code:

[User]
Text:
Screenshot 2022-10-25 1307161109×673 155 KB

Code:

[Assistant]
Text:Issue could be bindIp parameter
Check this link for Ipv6
Code:

[User]
Text:This are the settings, I turned back on the bindIpAll optionI checked firewall and created rules for mongod/mongos, set the network to private, flushed the DNS.
I have no idea what to do
Code:net:
  port: 27017
  bindIp: 127.0.0.1
  ipv6: true
  bindIpAll: true

[Assistant]
Text:You cannot use both bindIp & bindIp_all at same time
Use only one of them in your cfg file
Try 0.0.0.0 for bind_ip (not adviced on prod) and see if it works
Code:

[Assistant]
Text:Also check this for exact format for Ipv6 with localhost
Code:

[User]
Text:Thank you Ramachandra, but still nothing, I had the configuration suggested in the post you linked, now I have it like this, still nothing.I switched to node 19 (from 16), same with both versions. MongoDB v 6.0.2
Code:net:
  port: 27017
  ipv6: true
  bindIpAll: true

[Assistant]
Text:Is your IP whitelisted?
Did you try without Ipv6(use ipv4)
or
Don’t use bindipall and try other format given for ipv6 with localhost,::
Is your localhost mapped to 127.0.0.1?
Is the machine where your node.app runs same as db server?
Code:

[User]
Text:My IP is whitelisted
My localhost goes like this in the hosts fileI tried all the options and combinations, still nothing.
Mongod runs as window service, but I also tried stopping the service and launching a mongod instance on the ubuntu terminal (what I use normally) and I have the same results. Mongosh connects but node app doesn’t.
Code:

[Assistant]
Text:If mongosh connect then your application should connect if you run your application on the same machine as mongosh.  The following might indicates that you are using 2 machines or a VM:Mongod runs as window service, but I also tried stopping the service and launching a mongod instance on the ubuntu terminalIs the ubuntu terminal running on the same Windows where mongod is running as a service?  When you connect with mongosh, do you connect from the same Windows machine where mongod is running? Is the app running on the same machine as the mongosh that can connect?You shared a couple of version of your configuration file.  Please share the latest version.  Have you restarted mongod after changing the configuration file?
Code:

[User]
Text:Yeah same machine. I run mongosh on WSL terminal and it connects (with windows service running AND if I stop that service and run an instance of mongod on WSL).The latest configuration file. Mind that I’ve tried many combinations, this is from a MacOS where I tested and it worked fine.
Code:

[Assistant]
Text:I am not clear
How can Macos have Windows directory paths?
I have suggested in above posts to use 127.0.0.1,::1
Let’s wait for Steeves reply
Code:

[User]
Text:The directory path for mac is different of course, but that’s not the point. Can it be something about windows security or similar?
Code:

[Assistant]
Text:Share the content of the log.I would try without ipv6 true and without ::1 for bindIp, just to simplify things.
Code:

[User]
Text:
Code:{"t":{"$date":"2022-10-27T15:44:46.274+02:00"},"s":"I",  "c":"CONTROL",  "id":23285,   "ctx":"-","msg":"Automatically disabling TLS 1.0, to force-enable TLS 1.0 specify --sslDisabledProtocols 'none'"}
{"t":{"$date":"2022-10-27T15:44:47.112+02:00"},"s":"I",  "c":"NETWORK",  "id":4915701, "ctx":"thread1","msg":"Initialized wire specification","attr":{"spec":{"incomingExternalClient":{"minWireVersion":0,"maxWireVersion":17},"incomingInternalClient":{"minWireVersion":0,"maxWireVersion":17},"outgoing":{"minWireVersion":6,"maxWireVersion":17},"isInternalClient":true}}}
{"t":{"$date":"2022-10-27T15:44:47.113+02:00"},"s":"I",  "c":"NETWORK",  "id":4648602, "ctx":"thread1","msg":"Implicit TCP FastOpen in use."}
{"t":{"$date":"2022-10-27T15:44:47.115+02:00"},"s":"I",  "c":"REPL",     "id":5123008, "ctx":"thread1","msg":"Successfully registered PrimaryOnlyService","attr":{"service":"TenantMigrationDonorService","namespace":"config.tenantMigrationDonors"}}
{"t":{"$date":"2022-10-27T15:44:47.122+02:00"},"s":"I",  "c":"REPL",     "id":5123008, "ctx":"thread1","msg":"Successfully registered PrimaryOnlyService","attr":{"service":"TenantMigrationRecipientService","namespace":"config.tenantMigrationRecipients"}}
{"t":{"$date":"2022-10-27T15:44:47.122+02:00"},"s":"I",  "c":"REPL",     "id":5123008, "ctx":"thread1","msg":"Successfully registered PrimaryOnlyService","attr":{"service":"ShardSplitDonorService","namespace":"config.tenantSplitDonors"}}
{"t":{"$date":"2022-10-27T15:44:47.122+02:00"},"s":"I",  "c":"CONTROL",  "id":5945603, "ctx":"thread1","msg":"Multi threading initialized"}
{"t":{"$date":"2022-10-27T15:44:47.122+02:00"},"s":"I",  "c":"CONTROL",  "id":23316,   "ctx":"thread1","msg":"Trying to start Windows service","attr":{"serviceName":"MongoDB"}}
{"t":{"$date":"2022-10-27T15:44:47.123+02:00"},"s":"I",  "c":"CONTROL",  "id":4615611, "ctx":"initandlisten","msg":"MongoDB starting","attr":{"pid":15020,"port":27017,"dbPath":"C:/data/db","architecture":"64-bit","host":"LAPTOP-RJ5HAO5L"}}
{"t":{"$date":"2022-10-27T15:44:47.123+02:00"},"s":"I",  "c":"CONTROL",  "id":23398,   "ctx":"initandlisten","msg":"Target operating system minimum version","attr":{"targetMinOS":"Windows 7/Windows Server 2008 R2"}}
{"t":{"$date":"2022-10-27T15:44:47.123+02:00"},"s":"I",  "c":"CONTROL",  "id":23403,   "ctx":"initandlisten","msg":"Build Info","attr":{"buildInfo":{"version":"6.0.2","gitVersion":"94fb7dfc8b974f1f5343e7ea394d0d9deedba50e","modules":[],"allocator":"tcmalloc","environment":{"distmod":"windows","distarch":"x86_64","target_arch":"x86_64"}}}}
{"t":{"$date":"2022-10-27T15:44:47.123+02:00"},"s":"I",  "c":"CONTROL",  "id":51765,   "ctx":"initandlisten","msg":"Operating System","attr":{"os":{"name":"Microsoft Windows 10","version":"10.0 (build 22621)"}}}
{"t":{"$date":"2022-10-27T15:44:47.123+02:00"},"s":"I",  "c":"CONTROL",  "id":21951,   "ctx":"initandlisten","msg":"Options set by command line","attr":{"options":{"config":"C:\\Program Files\\MongoDB\\Server\\6.0\\bin\\mongod.cfg","net":{"bindIp":"127.0.0.1"},"service":true,"storage":{"dbPath":"C:\\data\\db"},"systemLog":{"destination":"file","logAppend":true,"path":"C:\\Program Files\\MongoDB\\Server\\6.0\\log\\mongod.log"}}}}
{"t":{"$date":"2022-10-27T15:44:47.124+02:00"},"s":"I",  "c":"STORAGE",  "id":22270,   "ctx":"initandlisten","msg":"Storage engine to use detected by data files","attr":{"dbpath":"C:/data/db","storageEngine":"wiredTiger"}}
{"t":{"$date":"2022-10-27T15:44:47.124+02:00"},"s":"I",  "c":"STORAGE",  "id":22315,   "ctx":"initandlisten","msg":"Opening WiredTiger","attr":{"config":"create,cache_size=7294M,session_max=33000,eviction=(threads_min=4,threads_max=4),config_base=false,statistics=(fast),log=(enabled=true,remove=true,path=journal,compressor=snappy),builtin_extension_config=(zstd=(compression_level=6)),file_manager=(close_idle_time=600,close_scan_interval=10,close_handle_minimum=2000),statistics_log=(wait=0),json_output=(error,message),verbose=[recovery_progress:1,checkpoint_progress:1,compact_progress:1,backup:0,checkpoint:0,compact:0,evict:0,history_store:0,recovery:0,rts:0,salvage:0,tiered:0,timestamp:0,transaction:0,verify:0,log:0],"}}
{"t":{"$date":"2022-10-27T15:44:47.369+02:00"},"s":"I",  "c":"STORAGE",  "id":4795906, "ctx":"initandlisten","msg":"WiredTiger opened","attr":{"durationMillis":245}}
{"t":{"$date":"2022-10-27T15:44:47.369+02:00"},"s":"I",  "c":"RECOVERY", "id":23987,   "ctx":"initandlisten","msg":"WiredTiger recoveryTimestamp","attr":{"recoveryTimestamp":{"$timestamp":{"t":0,"i":0}}}}
{"t":{"$date":"2022-10-27T15:44:47.372+02:00"},"s":"W",  "c":"CONTROL",  "id":22120,   "ctx":"initandlisten","msg":"Access control is not enabled for the database. Read and write access to data and configuration is unrestricted","tags":["startupWarnings"]}
{"t":{"$date":"2022-10-27T15:44:47.374+02:00"},"s":"I",  "c":"NETWORK",  "id":4915702, "ctx":"initandlisten","msg":"Updated wire specification","attr":{"oldSpec":{"incomingExternalClient":{"minWireVersion":0,"maxWireVersion":17},"incomingInternalClient":{"minWireVersion":0,"maxWireVersion":17},"outgoing":{"minWireVersion":6,"maxWireVersion":17},"isInternalClient":true},"newSpec":{"incomingExternalClient":{"minWireVersion":0,"maxWireVersion":17},"incomingInternalClient":{"minWireVersion":17,"maxWireVersion":17},"outgoing":{"minWireVersion":17,"maxWireVersion":17},"isInternalClient":true}}}
{"t":{"$date":"2022-10-27T15:44:47.375+02:00"},"s":"I",  "c":"REPL",     "id":5853300, "ctx":"initandlisten","msg":"current featureCompatibilityVersion value","attr":{"featureCompatibilityVersion":"6.0","context":"startup"}}
{"t":{"$date":"2022-10-27T15:44:47.375+02:00"},"s":"I",  "c":"STORAGE",  "id":5071100, "ctx":"initandlisten","msg":"Clearing temp directory"}
{"t":{"$date":"2022-10-27T15:44:47.375+02:00"},"s":"I",  "c":"CONTROL",  "id":20536,   "ctx":"initandlisten","msg":"Flow Control is enabled on this deployment"}
{"t":{"$date":"2022-10-27T15:44:47.639+02:00"},"s":"I",  "c":"FTDC",     "id":20625,   "ctx":"initandlisten","msg":"Initializing full-time diagnostic data capture","attr":{"dataDirectory":"C:/data/db/diagnostic.data"}}
{"t":{"$date":"2022-10-27T15:44:47.642+02:00"},"s":"I",  "c":"REPL",     "id":6015317, "ctx":"initandlisten","msg":"Setting new configuration state","attr":{"newState":"ConfigReplicationDisabled","oldState":"ConfigPreStart"}}
{"t":{"$date":"2022-10-27T15:44:47.642+02:00"},"s":"I",  "c":"STORAGE",  "id":22262,   "ctx":"initandlisten","msg":"Timestamp monitor starting"}
{"t":{"$date":"2022-10-27T15:44:47.644+02:00"},"s":"I",  "c":"NETWORK",  "id":23015,   "ctx":"listener","msg":"Listening on","attr":{"address":"127.0.0.1"}}
{"t":{"$date":"2022-10-27T15:44:47.644+02:00"},"s":"I",  "c":"NETWORK",  "id":23016,   "ctx":"listener","msg":"Waiting for connections","attr":{"port":27017,"ssl":"off"}}
{"t":{"$date":"2022-10-27T15:44:47.644+02:00"},"s":"I",  "c":"CONTROL",  "id":20555,   "ctx":"initandlisten","msg":"Service running"}

[Assistant]
Text:Any success?
It says waiting for connections but SSL:off
Did you try 0.0.0.0 inplace of localhost in your connect string.It is suggested as one of the fix in a forum thread
Code:

[User]
Text:Yes I tried it all. I think I’ll give up, thanks for your help anyways
Code:

[Assistant]
Text:Please share a screenshot that shows exactly how you start your application.If mongosh can connect, your application should connect.Are you using docker or some other container to start the application?I do not know exactly which commands are available inside WSL terminal, but the output of the following (if available)
Code:ss -tlnp
ps -aef | grep [m]ongo


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

[System] The following conversation has title: Mongod.service: Failed with result 'exit-code' and tags: []

[User]
Text:i have been using sudo sytemctl start mongod for while without having issues but lately whenever i run the same command to start mongodb and try to check the status i keep getting this failed message.how do i fix this?
Code:sudo sytemctl start mongodmongod.service - MongoDB Database Server
     Loaded: loaded (/lib/systemd/system/mongod.service; disabled; vendor preset: enabled)
     Active: failed (Result: exit-code) since Wed 2022-10-19 20:11:41 WAT; 47min ago
       Docs: https://docs.mongodb.org/manual
    Process: 5770 ExecStart=/usr/bin/mongod --config /etc/mongod.conf (code=exited, status=48)
   Main PID: 5770 (code=exited, status=48)

Oct 19 20:11:40  systemd[1]: Started MongoDB Database Server.
Oct 19 20:11:41  systemd[1]: mongod.service: Main process exited, code=exited, status=48/n/a
Oct 19 20:11:41  systemd[1]: mongod.service: Failed with result 'exit-code'.

[Assistant]
Text:Please share the content of the log file and configuration file.Also share the output of:If I remember correctly status=48 means you have another process listening at the same address/port.
Code:ps -aef | grep [m]ongo
ss -tlnp

[User]
Text:here’s my config file content Steeveps -aef | grep [m]ongo outputss -tlnpplease, how do i go about handling the status=48 ?
thanks.
Code:{"userId":"626bc8fbd5796d38ef89118f","telemetryAnonymousId":"626bc8fbd5796d38ef89118f","enableTelemetry":true,"disableGreetingMessage":true}
ps -aef | grep [m]ongo outputmongodb     2122       1  0 11:12 ?        00:00:07 /usr/bin/mongod --config /etc/mongodb.conf
ss -tlnpState        Recv-Q        Send-Q                    Local Address:Port                Peer Address:Port       Process
LISTEN       0             70                            127.0.0.1:33060                    0.0.0.0:*
LISTEN       0             4096                          127.0.0.1:27017                    0.0.0.0:*
LISTEN       0             151                           127.0.0.1:3306                     0.0.0.0:*
LISTEN       0             511                             0.0.0.0:80                       0.0.0.0:*
LISTEN       0             32                        192.168.122.1:53                       0.0.0.0:*
LISTEN       0             4096                      127.0.0.53%lo:53                       0.0.0.0:*
LISTEN       0             5                             127.0.0.1:631                      0.0.0.0:*
LISTEN       0             244                           127.0.0.1:5432                     0.0.0.0:*
LISTEN       0             244                           127.0.0.1:5433                     0.0.0.0:*
LISTEN       0             244                           127.0.0.1:5434                     0.0.0.0:*
LISTEN       0             244                           127.0.0.1:5435                     0.0.0.0:*
LISTEN       0             50                   [::ffff:127.0.0.1]:9614                           *:*           users:(("java",pid=2715,fd=17))
LISTEN       0             511                                [::]:80                          [::]:*
LISTEN       0             5                                 [::1]:631                         [::]:*

[User]
Text:I have been able to fixed the issue.
@steevej
The mongod service process  tries to  run on the same port and this was as a result of previously running mongod service with root privileged on ubuntu.
i had to kill the process on the port mongod service  is listening to without worrying if the service has been started by another user.
Code:sudo fuser -k 27017/tcp

[Assistant]
Text:I am sorry but I did missed the post you made 14 days ago.Thanks for sharing the solution.
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: Connect ECONNREFUSED 127.0.0.1:27017 and tags: ['node-js', 'server']

[User]
Text:I encounter this error message when I try to establish a connection, and my operating system is Windows. I have already tried reinstalling multiple times, but I can’t resolve it
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: Mongoose .populate() is not working with node.js app and tags: ['aggregation', 'node-js', 'data-modeling', 'mongoose-odm']

[User]
Text:First post here, so hello to everyone!I’m having trouble with mongoose populate because it’s apparently doing nothing. I’m going straight to the code.Here are my models:SpaceDayAnd the part of the controller where I have the getSpace route (/api/spaces/:id):And this is the result I get:I tried many things, but all the results were the same.Let me know if you need any other part of the code.Thank you all I expect the result to look something like this
Code:const spaceSchema = Schema(
	{
		user: {
			type: Schema.Types.ObjectId,
			required: true,
			ref: "User",
		},
		name: {
			type: String,
			required: true,
		},
		days: [{ type: Schema.Types.ObjectId, refPath: "Day" }],
	},
	{
		versionKey: false,
	        timestamps: true
        },
);

const Space = mongoose.model("Space", spaceSchema);

module.exports = Space;

const daySchema = Schema(
	{
		space: { type: Schema.Types.ObjectId, refPath: "Space" },
		date: {
			type: String,
			required: true,
		},
		water: {
			type: Boolean,
		},
		fertilizer: {
			type: Boolean,
		},
		transplant: {
			type: Boolean,
		},
		comment: {
			type: String,
		},
	},
	{
		versionKey: false,
	        timestamps: true
        },
);

const Day = mongoose.model("Day", daySchema);

module.exports = Day;
const getSpace = asyncHandler(async (req, res) => {
	const space = await Space.findById(req.params.id).populate("days");
	res.status(200).json(space);
});

{
    "_id": "63580115978dbf8f2f5a7a50",
    "user": "63501ab84613855834daa4ef",
    "name": "spaceName",
    "days": []
}
    "space": {
        "_id": "63580115978dbf8f2f5a7a50",
        "user": "63501ab84613855834daa4ef",
        "name": "spaceName",
        "days": [
            {
                "_id": "63581af565aed8cad3210046",
                "space": "63580115978dbf8f2f5a7a50",
                "date": "29/10/2022",
                "water": true,
                "fertilizer": true,
                "transplant": false,
                "comment": "This is a comment.",
                "createdAt": ...,
                "updatedAt": ...
            },
            {
                "_id": "63581af565aed8cad3210046",
                "space": "63580115978dbf8f2f5a7a50",
                "date": "29/10/2022",
                "water": false,
                "fertilizer": false,
                "transplant": true,
                "comment": "This is a comment.",
                "createdAt": ...,
                "updatedAt": ...
            }
        ]
    }

[Assistant]
Text:refPath doesn’t mean, what you might think it does. What you need here is a simple ref.
So, just change refPath to ref in your schemas and your example should be working as you expect.But, there is a second thing. You have redundant references: days refer to spaces and spaces to days. Generally you don’t need to refer to each other in both ways (unless in your specific use case you do). For many-to-one or many-to-many relations there are Populate Virtuals. You can read up on it in the Mongoose documentation.So I would get rid of the days field in the Space schema, and replace it with a populate virtual:
Code:refPathrefrefPathrefdaysconst spaceSchema = Schema(
	{
		user: {
			type: Schema.Types.ObjectId,
			required: true,
			ref: "User",
		},
		name: {
			type: String,
			required: true,
		},
	},
	{
		versionKey: false,
		timestamps: true,
	},
);

spaceSchema.virtual('days', {
	ref: 'Day',
	localField: '_id',
	foreignField: 'space',
});

const Space = mongoose.model("Space", spaceSchema);

module.exports = Space;


[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 count documents in pymongo and tags: ['aggregation', 'python']

[User]
Text:Hey People,
I know this is one of the most basic topics but I cant figure out where im going  wrong, trying . count() and .count_documents() and getting the following error:Cursor' object has no attribute 'count_documents
Cursor' object has no attribute 'count.the code im using is:im feeling quite dumb here…
Code: count().count_documents()Cursor' object has no attribute 'count_documentsCursor' object has no attribute 'counturi = "XXXXXXXXXX"
client = MongoClient(URI); # creating an instance of the client

print(client.sample_training.zips.find(
    {
        "pop" : {"$lt" : 1000}
    }

    ).count_documents())

[User]
Text:I figured out the answer, in case anyone else is interested:
Code:uri = "XXXXXXXXXX"
client = MongoClient(URI);

client.sample_training.zips.count_documents(
    {
        "pop" : {"$lt" : 1000}
    }
)


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

[System] The following conversation has title: Read change streams with multiple threads and tags: ['change-streams']

[User]
Text:Hi everyone,I have a question. Is there anyway to read change streams with multiple threads?Ex: we have 3 messages in change streams
messages = [A, B, C]
and my client has 2 threads. I want these 2 threads can receive messages in parallel. Ex:
thread 1: receive [A, C]
thread 2: receive [B]Assume that I don’t care about the ordering of messages, i.e: timestamp. I just want to read as fast as possible.
Code:messages = [A, B, C]

[Assistant]
Text:You can have multiple thread receiving different change stream message if the query used to set up the stream is different.If the query is the same then all receive the message.If you want to load balance you can easily do it internally or with any message queue framework.
Code:

[User]
Text:Basically, I want multiple threads can receive different messages in parallel from a change streams (ex: change streams from a specific collection in MongoDB).
It seems that there’s no way to do that.My problem is that I have 10.000 updates/sec in MongoDB. In my client program,  I want to receive these 10.000 messages via change streams (FULL_DOCUMENT, each document is around 100KB) with Java API of change streams. I want to speed this process up by using multiple threads (Assume that I don’t care about the ordering of messages).
Code:

[Assistant]
Text:(ex: change streams from a specific collection in MongoDB).
It seems that there’s no way to do that.please revise the documentation because you can do the above
Code:

[User]
Text:Thank Steeve for your reply.Could you please give me the link to that documentation? I’ve got stuck for a few days for this problem and couldn’t find any helpful link.I have 10k changes/sec in MongoDB. In my client program, I want to receive these 10k changes (fullDocument, each doc is around 100KB, so it’s around 1GB data/sec) with Java API of change streams.  I want to speed this process up by using multiple threads (assume that I don’t care about the ordering of messages). Below is a normal way to work with change streams. How to speed it up?
Code:        MongoCollection<Document> collection = db.getCollection("my_collection");
        ChangeStreamIterable<Document> iterable = collection.watch();

        iterable.forEach(new Consumer<ChangeStreamDocument<Document>>() {
            @Override
            public void accept(ChangeStreamDocument<Document> doc) {
                // do something with doc
            }
        });

[Assistant]
Text:Documentation can be found with google search.https://www.google.com/search?q=mongodb+change+streamsYou write(ex: change streams from a specific collection in MongoDB).
It seems that there’s no way to do that.but you share the codewhich does exactlychange streams from a specific collection
Code:MongoCollection<Document> collection = db.getCollection("my_collection");
ChangeStreamIterable<Document> iterable = collection.watch();

[User]
Text:Oh Steeve, maybe my explanation is pretty bad. What I want is “multiple threads can receive different messages in parallel from a change streams”. You can see the problem (10k changes/sec) that I described above.The key problem is I want “mutiple threads” and “parallel”.I mean I want to receive messages in parallel from change stream of something like: database, a single collection, multiple collections. So I wrote “ex: change streams from a specific collection”.Of course, I know how to receive message in single thread as same as the code that I shared. It’s easy.
Code:

[Assistant]
Text:As I originally wrote:If the query is the same then all receive the message.If you want to load balance you can easily do it internally or with any message queue framework.
Code:

[User]
Text:If the query is the same then all receive the message.yeah, so there’s no way to parallel the following codeIf we want to parallelize, we have to as follows but it’s very trickyI don’t understand this ideaIf you want to load balance you can easily do it internally or with any message queue framework.The main problem is how to parallelize if the query is the same? How to use message queue here? My pain point is that if the query is the same, we won’t be able to properly parallelize it without tricky. The bottleneck is if it’s the same query, the speed of reading from change stream is pretty bad.
Code:        ChangeStreamIterable<Document> iterable = collection.watch();
        iterable.forEach(new Consumer<ChangeStreamDocument<Document>>() {
            @Override
            public void accept(ChangeStreamDocument<Document> doc) {
                // do something with doc
            }
        });
ChangeStreamIterable<Document> iterable1 = collection.watch(query1); // query1 can be id in a specific range
ChangeStreamIterable<Document> iterable2 = collection.watch(query2);

[Assistant]
Text:If we want to parallelize, we have to as follows but it’s very trickyHow is that tricky?  The queries are different, they will receive different change stream events.Like you wrote:The main problem is how to parallelize if the query is the sameAs forHow to use message queue here?See how to use message queues - Google Search.If reading becomes the bottleneck you will have to distribute the load among different machines rather than multiple threads.
Code:ChangeStreamThread thread_query_1 = new ChangeStreamThread( query1 ).start() ;
ChangeStreamThread thread_query_2 = new ChangeStreamThread( query2 ).start() ;
class ChangeStreamThread extends Thread
{
  Document m_Query ;

  ChangeStreamThread( Document query )
  {
    m_Query = query ;
  }
  public void run()
  {
     // What ever code you have to process the events matching m_Query from the stream
  }
}

[User]
Text:Thank Steevej for your response.How is that tricky? The queries are different, they will receive different change stream events.The problem is it’s just a collection. Normally, we use a change stream for this collection as follows:The tricky is I split the change stream to multiple change streams by queries as I wrote (note that I just have 1 collection). So which queries should be chose?Of course, I can use 2 threads here with this 2 queries. The trick is I have to think about some queries to split a change stream to multiple change streams.So I want to use the same query (no query) as follows.How can I parallelize/use multi threads here?See how to use message queues - Google Search.My question is HOW to use it in MY USE CASE.If reading becomes the bottleneck you will have to distribute the load among different machines rather than multiple threads.There’re 2 things here:My client programMongoDBWhich thing did you suggest to scale?  client or mongo or both? Note that it’s just a single collection.
Maybe you suggests to distribute this collection to multiple mongo nodes (machines) and then will use different clients (on different machines), right?I haven’t had experiences about mongo. Sorry if there’re some stupid questions.
Code:ChangeStreamIterable<Document> iterable = collection.watch();
ChangeStreamIterable<Document> iterable1 = collection.watch(query1); // query1 can be id in a specific range
ChangeStreamIterable<Document> iterable2 = collection.watch(query2);
ChangeStreamIterable<Document> iterable = collection.watch();

[Assistant]
Text:I’m also experimenting with consuming change streams from multiple threads, and I guess it could be possible to do like this:
Code:        MongoCollection<SomeModel> events = test.getCollection("some-model", SomeModel.class);
        ChangeStreamIterable<SomeModel> watch = events.watch();
        ExecutorService executorService = Executors.newSingleThreadExecutor(); // adjust the thread pool as preferred
        executorService.execute(() -> {
            watch.forEach(csd -> {
                System.out.printnl("changeStreamDocument: " + csd); // this logic is called in each thread
            });
        });


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

[System] The following conversation has title: Intermittent MongoServerSelectionError when connecting from NodeJS using Google Cloud Run + MongoDB Atlas and tags: ['node-js', 'connecting']

[User]
Text:Hey folks,Hi, I’m having problems with connecting to MongoDB Atlas from a Google Cloud Run instance. I’m intermittently (a few times per day) getting a MongoServerSelectionError when my server is initializing and trying to connect. This is my current setup:I’m not seeing any alerts in MongoDB atlas. Please note that this is an intermittent issue. Sometimes it connects sometimes it doesn’t. Because my app currently has very low traffic there is never more than one instance running so the 30-second timeout + time to restart of the container makes this problem critical.Here’s the stack trace:MongoServerSelectionError: connection timed out at Timeout._onTimeout (/usr/src/app/node_modules/mongodb/lib/core/sdam/topology.js:438:30) at listOnTimeout (internal/timers.js:549:17) at processTimers (internal/timers.js:492:7) {
reason: TopologyDescription {
type: ‘ReplicaSetNoPrimary’,
setName: null,
maxSetVersion: null,
maxElectionId: null,
servers: Map {
‘xxx-00-00-0qvnm.gcp.mongodb.net:27017’ => [ServerDescription],
‘xxx-00-01-0qvnm.gcp.mongodb.net:27017’ => [ServerDescription],
‘xxx-00-02-0qvnm.gcp.mongodb.net:27017’ => [ServerDescription]
},
stale: false,
compatible: true,
compatibilityError: null,
logicalSessionTimeoutMinutes: null,
heartbeatFrequencyMS: 10000,
localThresholdMS: 15,
commonWireVersion: null
}Can anybody assist with troubleshooting this?Regards,
Stefan
Code:

[User]
Text:Sorry I’m on MongoDB version 4.2 not 4.4
Code:

[Assistant]
Text:Has this issue been resolved for you? I’m having the same issue, of intermittent connectivity due to a timeout, but mine is happening from a DigitalOcean droplet. I’ve tried almost everything, except use Mongoose.For my setup:
Code:Mongoose

[Assistant]
Text:I resolved it by setting useUnifiedTopology: false, works great now.
Code:useUnifiedTopology: false

[Assistant]
Text:I had a similar issue, however setting the useUnifiedTopology: false did not help me in my case.
Is there any other fixes to solve this error?
Code:useUnifiedTopology: false

[Assistant]
Text:Hi, I am new to MongoDB Atlas too. A few days ago, I had connection problem using Python. I have managed to find a solution for that.Just now, using MongoDB Atlas NodeJs tutorial, using the same Atlas connection string in my Python stuff. I had the below timeout error.It turned out, my Public IP address has changed because I reset my Windows 10 internet connection. I added the new Public IP to Atlast IP whitelist and it works.This is my case. I am new to this, I hope this might help someone…MongoServerSelectionError: connection  to 13.55.193.163:27017 closed
at Timeout._onTimeout (D:\Codes\nodejs\mongodb\node_modules\mongodb\lib\sdam\topology.js:312:38)
at listOnTimeout (node:internal/timers:557:17)
at processTimers (node:internal/timers:500:7) {
reason: TopologyDescription {
type: ‘ReplicaSetNoPrimary’,
servers: Map(3) {
‘cluster0-shard-00-00 . 71o6u . mongodb . net : 27017’ => [ServerDescription],
‘cluster0-shard-00-01.71o6u.mongodb.net 27017’ => [ServerDescription],
‘cluster0-shard-00-02.71o6u.mongodb.net:27017’ => [ServerDescription]
},
stale: false,
compatible: true,
heartbeatFrequencyMS: 10000,
localThresholdMS: 15,
setName: ‘atlas-vx7zhd-shard-0’,
logicalSessionTimeoutMinutes: undefined
}
}
Code:

[Assistant]
Text:This article helped me with this issue. Fixing MongoServerSelectionError while connecting MongoDB with node.js | by Barak Saidoff | Medium
Code:

[Assistant]
Text:@Stefan_Li Did you fix this? I have the same problem and cannot find a way to resolve it
Code:

[Assistant]
Text:Same - I also keep getting the error intermittently when using Cloud Run with Atlas.
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: Store and serve pdf documents and tags: []

[User]
Text:Good Morning.  I need to store and save pdf and doc documents.  Which is the best option?  Thank you
Code:

[Assistant]
Text:Good Morning @francisco_jose, welcome to MongoDB forum.In MongoDB, you use GridFS for storing files larger than 16 MB.If the files (i.e., each of them) to be stored are within the 16 MB limit of BSON document size, then you can store the files within a collection’s document as a field of type Binary Data (binData).
Code:binData

[User]
Text:Thanks for quick reply.  Still separate the data into two custer?  One for data related to pdf and the other for pdf?  Best regards
Code:

[Assistant]
Text:What are you considering - GridFS or within a document? What is the maximum size of the PDF documents?
Code:

[Assistant]
Text:In case of GridFS, the file and its information is stored in two collections (the files and chunks collections). The files stores the file’s metadata (information about the file like, id, length / size, filename, content type, etc.) and the chunks stores the actual file data.In case of a document as a file store, you can have additional fields specifying the file name, description etc., that is within the same document of the collection.
Code:fileschunksfileschunks

[Assistant]
Text:I tried importing pdf files to gridfs. As everything is stored in BSON, is it possible to export the pdf file from mongodb which I imported ?
Code:

[Assistant]
Text:Take a look at https://www.mongodb.com/docs/database-tools/mongofiles/#mongodb-binary-bin.mongofiles
Code:

[Assistant]
Text:Thank you. mongofiles command works
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: Extremely slow GraphQL performance even with very simple query and schema and tags: ['performance']

[User]
Text:I am trying to switch over from REST to GraphQL, and am experiencing horribly slow responses for queries. As in 5000-7000+ ms for a super simple, small request. I’ve spent days on this, tried everything, and am about to give up. Any help would be greatly appreciated.I have greatly reduced the schema from the huge one auto-generated to a tiny one for testing (no difference), implemented filters (no difference), simplified the query to only return a few, have indexed the main field (helped a tiny bit), and have not resolvers or anything special at all.I am on the M10 tier.The schema:The query:A sample log entry:I have an index on startDate as well. The result set is only 6k. Please help! Surely I am missing something, or there is some explanation, as this is completely unusable.Best,
Greg
Code:{
  "title": "mlbgame",
  "properties": {
    "_id": {
      "bsonType": "string"
    },
    "_simulation": {
      "bsonType": "bool"
    },
    "date": {
      "bsonType": "string"
    },
    "endDate": {
      "bsonType": "date"
    },
    "gameInfo": {
      "bsonType": "string"
    },
    "gameStatus": {
      "bsonType": "string"
    },
    "id": {
      "bsonType": "string"
    },
    "minutesRemaining": {
      "bsonType": "int"
    },
    "percentComplete": {
      "bsonType": "double"
    },
    "sport": {
      "bsonType": "string"
    },
    "startDate": {
      "bsonType": "date"
    },
    "status": {
      "bsonType": "string"
    }
  }
}
query GamesForCalendar($dateFrom: DateTime!, $dateTo: DateTime!) {
    mlbgames(query: {startDate_gte: $dateFrom, startDate_lte: $dateTo}) {
      id
      status
      sport
      date
      startDate
      endDate
      gameInfo
      gameStatus
      minutesRemaining
      percentComplete
      _simulation
    }
  }
Function Call Location:
US-OR
GraphQL Query:
query GamesForCalendar($dateFrom: DateTime!, $dateTo: DateTime!) { mlbgames(query: {startDate_gte: $dateFrom, startDate_lte: $dateTo}) { id status sport date startDate endDate gameInfo gameStatus minutesRemaining percentComplete _simulation __typename } }
Compute Used:
18736722090 bytes•ms
Remote IP Address:
136.32.230.69
Rule Performance Metrics:
{
  "dfsdb.mlbgames": {
    "roles": {
      "default": {
        "matching_documents": 19,
        "evaluated_fields": 0,
        "discarded_fields": 0
      }
    },
    "no_matching_role": 0
  }
}

[User]
Text:@Pavel_Duchovny Hi, did I post this incorrectly or in the wrong place? It would have sure been nige to give GraphGL with my application to see if it would have been best, but never could get past this issue. And no-one responded. I thought I did a decent job of describing the issue, so hoped it would have been an easy fix.Thanks.
Code:

[Assistant]
Text:Hi @Gregory_Fay sorry that we missed your original post! Do you happen to know the realm app deployment model and region that your atlas cluster is deployed in? Some things that may cause slower queries with GraphQL includeLet me know if one or more oof these things seems like it may be the issue here.
Code:

[User]
Text:Hi @Sumedha_Mehta1Thank you for the reply. I missed it, and it got buried. I had to go another direction for now but will try to recreate what I had and see if any of these suggestions solve the problem. I was so excited about GraphQL until I couldn’t get the basics to work!Thanks,
Greg
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: Best way to batch queries and tags: ['node-js']

[User]
Text:What is the best way to batch multiple queries into a single request? My goal is to avoid incurring the multiplied latency from serial requests, but also avoid opening too many connections for parallel requests. Ideally I would be able to say db.bulkRead([query1, query2, query3]) and get back a (potentially paginated) list of results.I’m also curious if the driver automatically does something like this (i.e. if I send two requests with maxPoolSize=1, will the driver wait for the first request to fully complete before issuing the second request? Or could it send both across a single connection, and just get the response streamed in after?). I would prefer a system where I could choose what to batch to ensure large queries aren’t mixed into batches of cheap queries.From my research so far, it seems like this exists but only with bulkWrites, and I’m not sure why it wouldn’t exist for bulkRead as well.
Code:

[Assistant]
Text:Hi @Alex_Coleman ,Making the poolsize to one will not increase on parallel execution of queries. On the other hand it will harm it.The best way to batch data fetch in MongoDB is to store it embedded in documents. Meaning that if you need to always fetch related data together store it together in a single document. If not possible store it in a chain of documents in a single collection with a predict that you can identify for example an id for a batch grab indexed.Other less recommended technics are using a unionWith aggregation or a $facet search with multiple facets as batches or $lookup to access different collections in a single query.I recommend reading some of our blogs on data designHave you ever wondered, "How do I model a MongoDB database schema for my application?" This post answers all your questions!A summary of all the patterns we've looked at in this seriesThanks
Pavel
Code:

[User]
Text:Hi Pavel,Thanks for the answer. I understand that a higher poolsize is best for parallel execution of queries, but I was just curious the exact effect of using a single connection. In particular, if execution was serial or just the writing of query/response to the DB was serial (which would be less of an issue since it doesn’t incur latency cost twice).I agree its best to store related data together in similar documents and such. However, across a large application issuing many queries it would be nice if there was a way to batch unrelated queries. Facet seems like exactly the answer I’m looking for, but it doesn’t support indexes on the contents. Do you know if there’s any way to do something similar? Basically I just want a {$or: [$query1, $query2]}, but with the results of each query labeled. Thanks!
Code: