0% found this document useful (0 votes)
89 views3 pages

Mongocommands

The document provides instructions for various MongoDB commands: - Creating a user with read and write roles to specific databases using db.createUser() - Deleting a user by switching to the desired database and using db.dropUser() - Exporting a database using mongodump and importing using mongorestore

Uploaded by

Vinamra Mittal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
89 views3 pages

Mongocommands

The document provides instructions for various MongoDB commands: - Creating a user with read and write roles to specific databases using db.createUser() - Deleting a user by switching to the desired database and using db.dropUser() - Exporting a database using mongodump and importing using mongorestore

Uploaded by

Vinamra Mittal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

command for creating user in mongodb.

use reporting
db.createUser(
{
user: "aryan",
pwd: "juWj8zZyxP2vbpfE",
roles: [
{ role: "read", db: "reporting" },(only for read)
{ role: "readWrite", db: "accounts" }(for both read and write roles)
]
}
)

deleting user in mongodb:

->switch to database from where you want to delete user using command: use db;
->then show users
->then choose the user want to remove by using this command:
db.dropUser("username")

importing and exporting in mongodb:


exporting:mongodump -d database_name -o output_directory

#################### Mongodump ########################################


mongodump --username {mongo username} --password {mongo password}
--authenticationDatabase "admin" --db {db name} --out /tmp/mongo-1Apr/
scp -r -i j.pem ec2-user@ip:/tmp/mongo-date ./

restore(import):mongorestore --username {mongo username} --password {mongo


password} --authenticationDatabase "admin" --db {db name} --collection
{collectionname} --drop /tmp/

/////////////////////to find users in mongodb:db.system.users.find() or


db.getUsers()

to get roles of databases:db.system.roles.find() (or) db.getRoles()

//////////////////to change password for the


user:db.changeUserPassword("accountUser", "SOh3TbYhx8ypJPxmt1oOfL")

to update mongo version:sudo yum install -y mongodb-org


sudo service mongodb reload

mongorestore --username alpha-healthcare-mongo --password 3TgryEfrHAdFGttMEus=


--authenticationDatabase "alpha_healthcare_live" --db alpha_healthcare_live
--collection tb_app_optional_fields --drop /tmp/

to create a database: use dbname


drop a database:db.dropDatabase()

to print collections:show collections


to print particular collection:db.collectionname.find() or
db.collectionname.find().pretty()
to drop collection: db.collectionname.drop()
to find count:db.collection.count()

//////db.collectionname.updateMany({},{$set:{'title':'New MongoDB Tutorial'}) to


update in the collection;

////////mongodb is NOSQL database.so there wont be particular schema in this case.


so not schema dump

tail -1000 /var/log/cron| grep mysql to check cron ran

<VirtualHost *:444>
ServerAdmin webmaster@localhost
ServerName dev-auth-goodman.capuchin.co

RewriteEngine On

RewriteCond %{HTTP:Accept-Language} ^en [NC]


RewriteRule ^/$ http:///dev-auth-goodman.capuchin.co/ [L,R=301]

DocumentRoot /apps/node-apps/dev/goodman-yelo-auth
ErrorLog /var/log/httpd/testweb_error.log
CustomLog /var/log/httpd/testweb_access.log combined
<Directory "/apps/node-apps/dev/goodman-yelo-auth">
AllowOverride All
Require all granted
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^ index.html
</Directory>
<Directory "/apps/node-apps/dev/goodman-yelo-auth">
AllowOverride All
Require all granted
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^ index.html
</Directory>
</VirtualHost>

Ajith#99599
ucbxuCXWZFz/iR7bANg=:

G9BDcTJYt3gKDTWF:
UqaNZyewZTcUNa9u

db.createUser(
{
user: "aryankanwar",
pwd: "hFWftryeEmWffy42",
roles: [
{ role: "readWrite", db: "atmtechnow_Live" }
]
}
)

You might also like