Debian Based System at /etc/mongodb.conf
auth = true
After running this command and set the security to enable on the conf file default connection cannot perform any administrative commands or view
any data hosted on mongoDB – server restart is requiered.
db.createUser({
user:”itdep_admin”,
pwd:”XXX”,
roles [{role:”userAdminAnyDatabase”,db:”admin”}]})
db.grantRolesToUser (“itdep_admin”,[{ role:”__system”,db:”admin”}]);
—IT has administrative commands —-Create Database Manager——
db.createUser(
{
user: “dbmanager”,
pwd: “SOMEPASSWORD”,
roles: [ { role: “dbOwner”, db: “mydb” }]
}
)
——-NO ADMINISTRATIVE commands——-Create Database read and Write——
db.createUser(
{
user: “read_write”,
pwd: “SOMEPASSWORD”,
roles: [ { role: “readWrite”, db: “mydb” }]
}
)
——————————Grant Example——————————–
–>db.grantRolesToUser (“dbmanager”,[{ role:”dbOwner”,db:”otherDB”}]);
–>db.grantRolesToUser (“read_write”,[{ role:”readWrite”,db:”otherDB”}]);
————–Connect————————-
mongo -u it_admin –authenticationDatabase admin -p SOME-DATABASE –port 28018
mongo -u dummy –authenticationDatabase mydb -p mydb –port 28018
————————SOME-COMMANDS FOR TESTING———————-
Create db mytest:
> use mytest
switched to db mytest
Create a collection hello:
> db.createCollection(“hello”)
{ “ok” : 1 }
Show all the collections there:
> db.getCollectionNames()
[ “hello”, “system.indexes” ]
Insert some dummy data:
> db.hello.insert({‘a’:’b’})
WriteResult({ “nInserted” : 1 })
Make sure it was inserted:
> db.hello.find()
{ “_id” : ObjectId(“55849b22317df91febf39fa9”), “a” : “b” }
Delete the collection and make sure it is not present any more:
> db.hello.drop()
true
> db.getCollectionNames()
[ “system.indexes” ]
######Exporting one collection
mongoexport –db mydb –collection tabl4 –out tabl4.json –port 28018 -u it_admin
######Exporting all collection in one database
mongodump -d mydb -o dump_mydb/ –port 28018 -u it_admin