MongoDB - Commands - Basic
MongoDB - Commands - Basic
https://stackoverflow.com/questions/41615574/mongodb-server-has-startup-warnings-
access-control-is-not-enabled-for-the-dat
https://www.mongodb.com/docs/v4.2/tutorial/enable-authentication/
8. Drop database (Enre you are connected to #mydb and then execute dropDatabase
command)
> db;
mydb
> db.dropDatabase();
{ "ok" : 1 }
>
Read Operation:
db.emp.find({"dept" : "IT"});
Update Operation:
db.emp.updateOne({"salary in usd" : 15}, {$set: {"salary in usd" : "16"}});
db.emp.updateMany({"dept" : "IT"}, { $set: {"salary in usd" : "13"}});
Delete Operation:
db.emp.deleteOne({"emp_name" : "emp1"});
12. mongoexport - in human-readable format. The data is in JSON format and CSV
format
used to Single collection
Syntax: mongoexport --host <hostname> --username <user_name> --password <password>
--db <database name> --collection <collection name> --out <output file>
example: mongoexport --db newdb --collection newcollection --out
/root/mongodump/newcollection.json --jsonArray
mongoexport --db newsun --collection newcollsun --out
/root/dump/newcollsun.json
14. mongoimport - restores the documents from the JSON file into the Mongo
collection
Syntax: mongoimport --host <hostname> --username <user_name> --password <password>
--db <database name> --collection <collection name> --file <imput file>
Example: mongoimport --db newsun --collection newcollsun --file
/root/mongodump/newcollection.json --jsonArray
mongoimport --db tuesday --collection twentyfive --file
/root/dump/newcollsun.json
16.
-----------------------------------------------------------------------------------
-------------------------------
3. To take export
Syntax: mongodump -d <database name> -o <backup-folder>
IonIdea: mongodump --host 10.91.0.213 --port 27017 -d deikaa -o
/tmp/deikaa_dump_24Feb2023
5. To drop database
> use mydb;
> db.dropDatabase();
/home/manju/deikaaprod/deikaadb/deikaa