In my application I am using MongoDB as the database and Express + Mongoose
for handling the codes. I have added a user to the database and given the readWrite
role for the user, now I can fetch the data from the database. But when I am trying to insert a collection using the save
function in Express + Mongoose
I got the following error message and I couldn't find how to add the findandmodify
privilege to the user.
{"name":"MongoError",
"ok":0,
"errmsg":"not authorized on od-database to execute command { findandmodify: \"identitycounters\",
query: {
field: \"id\",
model: \"Products\" },
new: 1 ,
remove: 0,
upsert: 0,
update: { $inc: { count: 1 } } }","code":13}
Please help me.
MongoDB: db.grantRolesToUser() method is used to grants an additional role and its privileges to a user. The name of the user to whom to grant roles. An array of additional roles to grant to the user. The level of write concern for the modification.
MongoDB – FindAndModify() Method. The findAndModify() method modifies and return a single document that matches the given criteria. By default, this method returns a pre-modification document. To return the document with the modifications made on the update, use the new option and set its value to true.
Definition. The findAndModify command modifies and returns a single document. By default, the returned document does not include the modifications made on the update. To return the document with the modifications made on the update, use the new option.
MongoDB: db.revokeRolesFromUser() method is used to remove a one or more roles from a user on the current database. The name of the user from whom to revoke roles. The roles to remove from the user. The level of write concern for the modification.
I test one user with readWrite
role to connect mongoDB
do the save
and findAndModify
operation on non-system document, both of them could be done successfully.
Please make sure
mongoose.createConnction
or mongoose.connect
.db.system.users
with readWrite
role.readWrite
user only can modify data on all non-system collections the system.js collectionIf you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With