Reputation: 2526
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.
Upvotes: 9
Views: 1768
Reputation: 2756
If bypassDocumentValidation
is specified for findAndModify
, the dbAdmin
role, or a custom role with the bypassDocumentValidation
permission is needed.
The boolean parameters should preferably be specified as true
or false
instead of 0
and 1
as well
Upvotes: 0
Reputation: 48376
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 collectionUpvotes: 1
Reputation: 2756
Or try to disable authorization or add user that connects to the database.
An example of adding a user to the database:
db.createUser({
user: "admin",
pwd: "test",
roles: [ { role: "dbAdmin", db: "shop" } ]
})
Where:
db:"shop"
- is name database pwd: "test"
- password databaseuser: "admin"
- the user through which the connection to the database, example db.auth('admin', 'test')
Upvotes: 0