I check to see if the db name is in atlas I update it but if the db is not I create the db . My code is something like :
`async function isDbExist(dbName) {
let {MongoClient} = require('mongodb') ;
let client = await new MongoClient(urlToAtlasCluster)
if(! (await client.db(dbName).listCollections.toArray().length)) {
// db is not in atlas … createDb()
}
}`
I know that I could have used the cursor returned by ‘listCollections’ to enhance performance .
But is there any way I can listdatabases in node application without using this lame workaround !!
alexbevi , thank you for your reply . This answers my question, and the quality of the code you provided is mind blowing . I think I need to learn more about these commands that are callable on any db like :
client.(‘dbName’).command({dbStats:1}) ;
and others .
Thank you again
Thank you for taking the time to add to your reply , I think I will be fine with this way :
Because it is consistent with how you would work with other databases that has your actual data .
I’m , however, thankful for you and ahighly appreciate your help . This community might be the best community I have ever seen ! quick relpy , percise info and even high quality code !
If you can link to a documentation where I can find all the classes of nodejs mongodb driver and the related methods I will appreciate it . What I am looking for is a documentation that takes the style of nodejs documentation style , like :
Class : MongoClient
MongoClient.db (dbName):
dbName : String
returns : object to manipulate database …
I am not aware of any documentations like this !
Thank you again !