DEV Community

Idriss
Idriss

Posted on

Transactions on Node.js with MongoDB

On node,js if you have difficulties trying to run transactions with MongoDB.
Connect to mongodb shell (mongosh on macOS) and create an admin user if you don't have one with the command

db.createUser({
user: "myUser",
pwd: "myPassword",
roles: [
{ role: "userAdminAnyDatabase", db: "admin" },
"readWriteAnyDatabase"
]
});

.

Update him with
`
'

'db.updateUser("myUser", {
  roles: [
    { role: "myPassword", db: "admin" }
  ]
});''`
Enter fullscreen mode Exit fullscreen mode

Depending on your operating system, find the configuration file of mongodb(mongod.conf). Make sure the attribute ''replication'' is enabled with ''replSetName: "rs0"'' .

Go in the mongodb shell and run ''rs.initiate()'' if it asked you to authenticate first, use the admin credentials

Top comments (0)