-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexperiment21 noSql
134 lines (102 loc) · 4.66 KB
/
experiment21 noSql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
EXPERIMENT NO.21 NoSQL – ADMINISTRATION
=======================================
`````````````````````````````````````````````````````````````````````````````````````````````````````
1.Write a MongoDB query to create a user “CUSTOMER1” and grant the read role in the INVOICE database.
=====================================================================================================
> db.createUser({user:"CUSTOMER1",pwd:"1234",roles:[{role:"read",db:"invoice"}]})
Successfully added user: {
"user" : "CUSTOMER1",
"roles" : [
{
"role" : "read",
"db" : "invoice"
}
]
}
`````````````````````````````````````````````````````````````````````````````````````````````````````
2.Write a MongoDB query to create the backup for the INVOICE database.
=====================================================================================================
ubuntu@aswin:~$ mkdir mongo_bck
ubuntu@aswin:~$ cd mongo_bck
ubuntu@aswin:~/mongo_bck$ mongodump -d invoice -o ~/mongo_bck/first_backup
2022-06-14T19:35:19.746+0530 writing invoice.CUSTOMER to /home/ubuntu/mongo_bck/first_backup/invoice/CUSTOMER.bson
2022-06-14T19:35:19.746+0530 writing invoice.PRODUCT to /home/ubuntu/mongo_bck/first_backup/invoice/PRODUCT.bson
2022-06-14T19:35:19.746+0530 done dumping invoice.PRODUCT (5 documents)
2022-06-14T19:35:19.747+0530 done dumping invoice.CUSTOMER (4 documents)
ubuntu@aswin:~/mongo_bck$ ls
first_backup
ubuntu@aswin:~/mongo_bck$ ls -l first_backup
total 4
drwxrwxr-x 2 ubuntu ubuntu 4096 Jun 14 19:35 invoice
ubuntu@aswin:~/mongo_bck$ cd ./first_backup/invoice
ubuntu@aswin:~/mongo_bck/first_backup/invoice$ ls -l
total 16
-rw-rw-r-- 1 ubuntu ubuntu 336 Jun 14 19:35 CUSTOMER.bson
-rw-rw-r-- 1 ubuntu ubuntu 164 Jun 14 19:35 CUSTOMER.metadata.json
-rw-rw-r-- 1 ubuntu ubuntu 265 Jun 14 19:35 PRODUCT.bson
-rw-rw-r-- 1 ubuntu ubuntu 163 Jun 14 19:35 PRODUCT.metadata.json
ubuntu@aswin:~/mongo_bck/first_backup/invoice$ tree ~/mongo_bck
/home/ubuntu/mongo_bck
└── first_backup
└── invoice
├── CUSTOMER.bson
├── CUSTOMER.metadata.json
├── PRODUCT.bson
└── PRODUCT.metadata.json
2 directories, 4 files
> show dbs
admin 0.000GB
config 0.000GB
invoice 0.000GB
local 0.000GB
> use invoice
switched to db invoice
> show collections
CUSTOMER
PRODUCT
> db.dropDatabase();
{ "dropped" : "invoice", "ok" : 1 }
> show dbs
admin 0.000GB
config 0.000GB
local 0.000GB
>
//RESTORE COMMAND
ubuntu@aswin:~$ mongorestore ~/mongo_bck/first_backup
2022-06-14T19:44:10.216+0530 preparing collections to restore from
2022-06-14T19:44:10.216+0530 reading metadata for invoice.CUSTOMER from /home/ubuntu/mongo_bck/first_backup/invoice/CUSTOMER.metadata.json
2022-06-14T19:44:10.216+0530 reading metadata for invoice.PRODUCT from /home/ubuntu/mongo_bck/first_backup/invoice/PRODUCT.metadata.json
2022-06-14T19:44:10.223+0530 restoring invoice.PRODUCT from /home/ubuntu/mongo_bck/first_backup/invoice/PRODUCT.bson
2022-06-14T19:44:10.224+0530 no indexes to restore
2022-06-14T19:44:10.224+0530 finished restoring invoice.PRODUCT (5 documents, 0 failures)
2022-06-14T19:44:10.228+0530 restoring invoice.CUSTOMER from /home/ubuntu/mongo_bck/first_backup/invoice/CUSTOMER.bson
2022-06-14T19:44:10.229+0530 no indexes to restore
2022-06-14T19:44:10.229+0530 finished restoring invoice.CUSTOMER (4 documents, 0 failures)
2022-06-14T19:44:10.229+0530 9 document(s) restored successfully. 0 document(s) failed to restore.
> show dbs
admin 0.000GB
config 0.000GB
invoice 0.000GB
local 0.000GB
>
invoice database restored
`````````````````````````````````````````````````````````````````````````
3.Write a MongoDB query to restore a particular database or a collection.
=========================================================================
Droping collection PRODUCT and then we need to restore it agian
> db.PRODUCT.drop()
true
> show collections
CUSTOMER
ubuntu@aswin:~$ mongorestore --db invoice --collection PRODUCT ~/mongo_bck/first_backup/invoice/PRODUCT.bson
2022-06-14T19:56:53.617+0530 checking for collection data in /home/ubuntu/mongo_bck/first_backup/invoice/PRODUCT.bson
2022-06-14T19:56:53.618+0530 reading metadata for invoice.PRODUCT from /home/ubuntu/mongo_bck/first_backup/invoice/PRODUCT.metadata.json
2022-06-14T19:56:53.633+0530 restoring invoice.PRODUCT from /home/ubuntu/mongo_bck/first_backup/invoice/PRODUCT.bson
2022-06-14T19:56:53.695+0530 no indexes to restore
2022-06-14T19:56:53.695+0530 finished restoring invoice.PRODUCT (5 documents, 0 failures)
2022-06-14T19:56:53.695+0530 5 document(s) restored successfully. 0 document(s) failed to restore.
> show collections
CUSTOMER
PRODUCT
collection 'PRODUCT' has restored
//VERIFIED