Why does MongoDB (Version 3.2) creates two connections instead of one?

82 views
Skip to first unread message

Mayank Jain

unread,
Apr 13, 2016, 3:23:40 PM4/13/16
to mongodb-user
Hi,

I have noticed that after I create a connection, and do say an insert mongodb creates another connection.

I have seen this behaviour with mongodb python and clojure (which uses java) library both.

Here's an example of how to reproduce it:

from pymongo import MongoClient


## Run `db.serverStatus().connections`via mongo shell to check the current number of connections
client
= MongoClient()


## Run the `db.serverStatus().connections` command again, it should increment by 1
client
.test_database.posts.insert_one({"author": "Mike"}).inserted_id
## Now if you run `db.serverStatus().connections` command again, it again increments by 1

##But if you repeat insert (or any other command besides createing a new connection) it wont create another connection

I am using:
Python        - 3.5.1
Mac OSX       - 10.10.5
Mongo Version - 3.2.4

Is this expected? Has anyone else seen this?

Thanks.

Jason Carey

unread,
Apr 14, 2016, 6:12:12 PM4/14/16
to mongod...@googlegroups.com
Mayank,

You may be seeing the Monitor Thread.  Drivers are required by the MongoDB Server Discovery and Monitoring Specification to do a variety of background health checks to monitor the topology behind a given MongoDB URI.  This catches things like replica set failover, the addition of new mongos' in sharding, etc.

Most drivers handle this with a background thread, those that don't are forced to periodically block during processing instead.

-Jason

--
You received this message because you are subscribed to the Google Groups "mongodb-user"
group.
 
For other MongoDB technical support options, see: https://docs.mongodb.org/manual/support/
---
You received this message because you are subscribed to the Google Groups "mongodb-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mongodb-user...@googlegroups.com.
To post to this group, send email to mongod...@googlegroups.com.
Visit this group at https://groups.google.com/group/mongodb-user.
To view this discussion on the web visit https://groups.google.com/d/msgid/mongodb-user/96895ac1-a6a5-4cbb-8f29-7d567e005486%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--

{ name     : "Jason Carey",
  title    : "Software Engineer",
  location : "New York, NY",
  twitter  : ["@MongoDB""@MongoDBInc"],
  facebook : ["MongoDB""MongoDB, Inc."] }

Mayank Jain

unread,
Apr 20, 2016, 1:27:38 AM4/20/16
to mongodb-user
Thanks :)
Reply all
Reply to author
Forward
0 new messages