Need to understand open connection concept of mongodb with golang

I have written the below program (sample for connection & query run) and not Disconnect the client to check open files with mongodb query. When I use simple connection & after than 10 queries in loop then it will open 3 resources. 2 for connection & 1 for multiple queries that I will run with that client.
But when I use convert the same program with go-routines then open connections increases 7-8. Can you please expalin how mongodb open resources ? & why pooling not work as expected in case of go routine.

package main

import (


func main() {
	// Create a MongoDB connection
	clientOptions := options.Client().ApplyURI("mongodb://localhost:27017")
	client, err := mongo.Connect(context.Background(), clientOptions)
	if err != nil {
	// defer client.Disconnect(context.Background()) // Close the connection when done

	// Ping the MongoDB server and check for errors
	err = client.Ping(context.Background(), nil)
	if err != nil {
	fmt.Println("Connected to MongoDB!")

	// Get a pointer to the database and collection
	db := client.Database("test")
	collection := db.Collection("users")

	// Run a query on the collection
	// For example, insert a document
	res, err := collection.InsertOne(context.Background(), map[string]string{"name": "Alice", "age": "25"})
	if err != nil {
	fmt.Println("Inserted document with ID:", res.InsertedID)
	var resp bson.M
	err = collection.FindOne(context.TODO(), bson.M{"_id": res.InsertedID}).Decode(&res)
	fmt.Println("res", resp, err)

Using default clientOptions the maxPoolSize is 100. So I think this is consistent with the options you provided on the Connect()

@Swati_Sharma the Go Driver connection pool will open a new connection anytime there is an operation waiting to run and there are no idle connections, unless the maximum pool size is reached.

When operations are run sequentially (i.e. in the same goroutine), the next operation never begins until the previous one completes, so there is only one request for a connection at a time. However, when operations are run in separate goroutines, there may be many simultaneous requests for connections. In response, the Go Driver creates more connections to serve the waiting operations. Those connections will still be reused for subsequent operations.

As @chris mentioned, you can limit the number of connections each connection pool will maintain using maxPoolSize or SetMaxPoolSize.

ok thank you for your clarification