Home > AI > Database > MongoDB >

MongoDB create a user with only Read privilege

Step 1, enter the MongoDB with admin privilege

$ mongo
$ use admin
MongoDB Enterprise > db.auth("admin","wysheid")   # provide admin user and password

Step2, create a user with only Read privilege

MongoDB Enterprise > db.createUser({user: "user1",pwd: "test", roles: [{role:"read", db: "school"}]})

Step3, enter the MongoDB with the new user to test

$ mongo
MongoDB Enterprise > db.auth("user1","test") 
MongoDB Enterprise > use school 
MongoDB Enterprise > show collections 
MongoDB Enterprise > db.class.find() 

Leave a Reply