You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When using the feathers CLI it generates a mongodb.js file, the mongodbClient is stored in app and used when setting up mongoDb services. My question is when I use app.get('mongodbClient') do I need to close the client connections, also I could not use it to startSession ...so I added dbClient is this a good thing and do i need to terminate connection after using it.
/// mongodb.jsimport{MongoClient}from'mongodb'exportconstmongodb=app=>{constconnection=app.get('mongodb')constdatabase=newURL(connection).pathname.substring(1)//added this so I can use the Session in transactionsconstmongoClient=MongoClient.connect(connection).then((client)=>client)// cant I use this instead for transactions constmongoDbClient=MongoClient.connect(connection).then((client)=>client.db(database))// when using these do I need to close the connection after using them app.set('dbClient',mongoClient)//added this tooapp.set('mongodbClient',mongoDbClient)}/// Method using Transaction in some serviceasyncfoo(){constclient=awaitthis.app.get('dbClient')constsession=client.startSession()try{awaitsession.withTransaction(async()=>{// do some work})}finally{awaitsession.endSession()awaitclient.close()// do i need to close connection}}
In the service.class.js files the getOptions method calls app.get('mongodbClient') is this the only place in feathers where they are used and do connection need to be closed after.....am confused am getting the feeling that multiple connection are made to the database and left open.. Thank you
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
When using the feathers CLI it generates a mongodb.js file, the mongodbClient is stored in app and used when setting up mongoDb services. My question is when I use app.get('mongodbClient') do I need to close the client connections, also I could not use it to startSession ...so I added dbClient is this a good thing and do i need to terminate connection after using it.
In the service.class.js files the getOptions method calls app.get('mongodbClient') is this the only place in feathers where they are used and do connection need to be closed after.....am confused am getting the feeling that multiple connection are made to the database and left open.. Thank you
Beta Was this translation helpful? Give feedback.
All reactions