sarah w
sarah w

Reputation: 3485

why 2 connections open when calling MongoClient instance in mongodb

this following code is getting mongodb connection

val SERVER:ServerAddress = {

val hostName=config.getString("db.hostname")

val port=config.getString("db.port").toInt
        new ServerAddress(hostName,port)
          }

val DATABASE:String   = config.getString("db.dbname")

val connectionMongo = MongoConnection(SERVER)

i think it should create one connection but in mongod console it shows 2 connection why is this happening

2016-06-24T16:20:15.412+0500 [initandlisten] waiting for connections on port 27017
2016-06-24T16:20:38.543+0500 [initandlisten] connection accepted from 127.0.0.1:45712 #1 (1 connection now open)
2016-06-24T16:20:38.560+0500 [initandlisten] connection accepted from 127.0.0.1:45713 #2 (2 connections now open)

Upvotes: 1

Views: 1396

Answers (1)

evanchooly
evanchooly

Reputation: 6233

MongoClient maintains a connection pool internally. The default size is 10, iirc, and is lazily populated. What you're likely seeing is the driver connecting to the server to do various housekeeping work such as topology discovery.

Upvotes: 4

Related Questions