I'm very new to Javascript and I am trying to connect to a mongodb database by following this guide.
const {MongoClient} = require('mongodb')
/*
Username: myusername
Key: mykey
*/
connString = 'mongodb+srv://<myusername>:<mykey>@' +
'cluster0.vpss6.mongodb.net/<dbname>?' +
'retryWrites=true&w=majority'
const client = new MongoClient(connString, {useUnifiedTopology: true})
databaseList = client.db().admin().listDatabases()
databaseList.then(function(result) {
console.log(result)
})
Whenever I omit the {}
around the {MongoClient}
line the code breaks I receive a Uncaught TypeError: client.db is not a function
error message further down at the databaseList = client.db().admin().listDatabases()
line. This also applies to when I switch the const
declarations to var
declarations.
Why is this?