mongodb commands
for backup:-
$ mongodump --db healyosdb --out /home/ec2-user/mongobackup/`date +"%m-%d-%y"`
creating user with pass
mongo --version
install
wget https://repo.mongodb.org/yum/redhat/7/mongodb-org/3.0/x86_64/RPMS/mongodb-org-server-3.0.15-1.el7.x86_64.rpm
use DATABASE_NAME
Your created database (mydb) is not present in list. To display database, you need to insert at least one document into it.
>db.movie.insert({"name":"tutorials point"}) >show dbs local 0.78125GB mydb 0.23012GB test 0.23012GB
Next, make sure that your administrative user is able to authenticate properly by running the following mongo command to connect as this user. This command includes the -u flag, which precedes the name of the user you want to connect as. Be sure to replace AdminSammy with your own administrative user’s username. It also includes the -p flag, which will prompt you for the user’s password, and specifies admin as the authentication database where the specified username was created:
Adding the User
Use the db.createUser() method to add the user to the specified database. Adding a user with options is easy, it’s essentially inserting a user document into a NoSQL database!
use reporting // specify the DB
db.createUser(
{
user: "reportsUser",
pwd: passwordPrompt(), // or cleartext password if you wish
roles: [
{ role: "read", db: "reporting" },
{ role: "read", db: "products" },
{ role: "read", db: "sales" },
{ role: "readWrite", db: "accounts" }
]
}So, I've finally figured this out. Note, this fix only works for Mongo 2.4.
In 2.4 you can specify a database to authenticate yourself with in the connection string or on the command line
So to create the initial user
root@vmi1115207:/var/log/mongodb# mongo --version
MongoDB shell version v3.6.8
use admin
db.createUser({user: "foo" , pwd: "bar", roles: [ "userAdminAnyDatabase","readWriteAnyDatabase" ]})
Comments
Post a Comment