0

How the tcp connection is established and closed during the database call?

The below code is to get lists of databases in mongodb using mongoclient in nodejs

async function main(){

    const uri = "mongodb+srv://<username>:<password>@<your-cluster-url>/test?retryWrites=true&w=majority";
 

    const client = new MongoClient(uri);
 
    try {
       
        await client.connect();
 
        await  listDatabases(client);

    } catch (e) {
        console.error(e);
    } finally {
        await client.close();
    }
}
main().catch(console.error);

1.Does the "await client.connect()" establish a tcp connection with mongoDb?

2.Does the "await client.close()"close a tcp connection with mongoDb?

3.How does the mongodb and nodejs communicate using tcp ?

1 Answer 1

0

node-mongodb-native's .connect() and .close() manage a Topology of Servers that have Monitored Connections communicating via a MessageStream

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.