Cant read or write to atlas database

Im new to mongodb, can someone explain to me how can i authenticate using SCRAM?

I tried writing to the database, but it returned this error: UnhandledPromiseRejectionWarning: MongoServerError: (Unauthorized) not authorized on admin to execute command

This is my code for the client:

 const { MongoClient, ServerApiVersion } = require('mongodb');
  const uri = "mongodb+srv://QuackDev:" + password + "";
  const client = new MongoClient(uri, {
    serverApi: {
      version: ServerApiVersion.v1,
      strict: true,
      deprecationErrors: true,

Am i doing something wrongly?

It does not work, so yes you are doing something wrong. But the issue is simply because you are trying to read or write in the admin database rather than your database.

Look at to see how to specify a different database.

That resolved my issue :sweat_smile:
Thanks for your help!

1 Like