I have some confusion. I’ve succesfully implemented a few CRUD applications that connect to DBs hosted on Mongo Atlas. Every time, I do this:
const client = new MongoClient(<connectionString>); const db = client.db(<dbName>)
And then I’m off to the races with queries on db.
For the first time, I’ve considered it crucial to carry out queries within a transaction. So I know I’m dealing with sessions now, and upon some research, to deal with a session I’m supposed to use client.connect().
I’m confused because I’ve never used the connect() method - but according to MongoDB documentation I shouldn’t even be able to interact with my database without establishing connection.
So what gives? It really seems like the MongoClient constructor is automatically establishing connection to me - but I can’t find any documentation to back that up.
Tangentially (but also to the actual need I have), if I’m connecting to a db fine with client.db(), does that mean that I’m also likely to succeed with client.startSession().
Thanks for any help.
Edit to add:
And further - I’m never closing a connection (I’m never opening one in the first place that I can tell…) - would it be any different when working with a session? I know I have to end the session.