-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup_mongodb.sh
executable file
·221 lines (212 loc) · 5.89 KB
/
setup_mongodb.sh
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
#!/bin/bash
# This is only used for testing purposes.
# Pull the MongoDB image
docker pull mongo:latest
# Run MongoDB container
docker run -d --name mongodb-test -p 27017:27017 mongo:latest
# Wait for MongoDB to start
sleep 5
# Create a database and load sample data
docker exec -it mongodb-test mongosh --eval "
db = db.getSiblingDB('testdb');
// Users collection
db.users.insertMany([
{
_id: ObjectId(),
username: 'alice123',
email: '[email protected]',
age: 28,
isActive: true,
registrationDate: new Date('2023-01-15'),
lastLogin: ISODate('2023-09-30T14:30:00Z'),
preferences: { theme: 'dark', notifications: true },
tags: ['developer', 'nodejs'],
scores: [85, 92, 78, 95]
},
{
_id: ObjectId(),
username: 'bob456',
email: '[email protected]',
age: 35,
isActive: false,
registrationDate: new Date('2022-11-20'),
lastLogin: ISODate('2023-08-15T09:45:00Z'),
preferences: { theme: 'light', notifications: false },
tags: ['designer', 'ui/ux'],
scores: [88, 76, 92, 81]
},
{
_id: ObjectId(),
username: 'charlie789',
email: '[email protected]',
age: 42,
isActive: true,
registrationDate: new Date('2023-03-05'),
lastLogin: ISODate('2023-09-28T11:20:00Z'),
preferences: { theme: 'auto', notifications: true },
tags: ['manager', 'agile'],
scores: [91, 88, 95, 87]
},
{
_id: ObjectId(),
username: 'david101',
email: '[email protected]',
age: 31,
isActive: true,
registrationDate: new Date('2023-02-10'),
lastLogin: ISODate('2023-09-29T16:55:00Z'),
preferences: { theme: 'dark', notifications: false },
tags: ['tester', 'qa'],
scores: [79, 85, 88, 92]
},
{
_id: ObjectId(),
username: 'eve202',
email: '[email protected]',
age: 39,
isActive: true,
registrationDate: new Date('2022-12-01'),
lastLogin: ISODate('2023-09-30T10:15:00Z'),
preferences: { theme: 'light', notifications: true },
tags: ['devops', 'cloud'],
scores: [94, 89, 92, 87]
}
]);
// Products collection
db.products.insertMany([
{
_id: ObjectId(),
name: 'Smartphone X',
category: 'Electronics',
price: 599.99,
inStock: 50,
features: ['5G', 'Dual Camera', 'Face ID'],
dimensions: { width: 7.5, height: 15.0, depth: 0.8 },
releaseDate: new Date('2023-05-15'),
ratings: [4.5, 4.8, 4.2, 4.6, 4.7]
},
{
_id: ObjectId(),
name: 'Laptop Pro',
category: 'Electronics',
price: 1299.99,
inStock: 25,
features: ['16GB RAM', 'SSD', 'Retina Display'],
dimensions: { width: 30.41, height: 21.24, depth: 1.56 },
releaseDate: new Date('2023-03-10'),
ratings: [4.8, 4.9, 4.7, 4.8, 4.6]
},
{
_id: ObjectId(),
name: 'Wireless Earbuds',
category: 'Audio',
price: 129.99,
inStock: 100,
features: ['Noise Cancelling', 'Waterproof', 'Long Battery Life'],
dimensions: { width: 2.1, height: 1.8, depth: 2.5 },
releaseDate: new Date('2023-01-20'),
ratings: [4.3, 4.5, 4.4, 4.2, 4.6]
},
{
_id: ObjectId(),
name: 'Smart Watch',
category: 'Wearables',
price: 249.99,
inStock: 75,
features: ['Heart Rate Monitor', 'GPS', 'Water Resistant'],
dimensions: { width: 3.4, height: 4.4, depth: 1.3 },
releaseDate: new Date('2023-04-05'),
ratings: [4.4, 4.6, 4.3, 4.5, 4.7]
},
{
_id: ObjectId(),
name: 'Ultra HD TV',
category: 'Electronics',
price: 799.99,
inStock: 30,
features: ['4K', 'Smart TV', 'HDR'],
dimensions: { width: 122.0, height: 71.0, depth: 6.4 },
releaseDate: new Date('2023-02-28'),
ratings: [4.7, 4.8, 4.6, 4.9, 4.7]
}
]);
// Orders collection
db.orders.insertMany([
{
_id: ObjectId(),
userId: ObjectId(),
orderDate: new Date('2023-09-15'),
status: 'Shipped',
totalAmount: '729.98',
items: [
{ productId: ObjectId(), quantity: 1, price: '599.99' },
{ productId: ObjectId(), quantity: 1, price: '129.99' }
],
shippingAddress: {
street: '123 Main St',
city: 'Anytown',
state: 'CA',
zipCode: '12345'
},
paymentMethod: 'Credit Card',
lastFourDigits: '1234'
},
{
_id: ObjectId(),
userId: ObjectId(),
orderDate: new Date('2023-09-20'),
status: 'Processing',
totalAmount: '1299.99',
items: [
{ productId: ObjectId(), quantity: 1, price: '1299.99' }
],
shippingAddress: {
street: '456 Elm St',
city: 'Another Town',
state: 'NY',
zipCode: '67890'
},
paymentMethod: 'PayPal',
paypalTransactionId: 'PAY-1234567890ABCDEF'
},
{
_id: ObjectId(),
userId: ObjectId(),
orderDate: new Date('2023-09-25'),
status: 'Delivered',
totalAmount: '379.98',
items: [
{ productId: ObjectId(), quantity: 1, price: 249.99 },
{ productId: ObjectId(), quantity: 1, price: 129.99 }
],
shippingAddress: {
street: '789 Oak St',
city: 'Somewhere',
state: 'TX',
zipCode: '54321'
},
paymentMethod: 'Credit Card',
lastFourDigits: '5678'
},
{
_id: ObjectId(),
userId: ObjectId(),
orderDate: new Date('2023-09-30'),
status: 'Pending',
totalAmount: '799.99',
items: [
{ productId: ObjectId(), quantity: 1, price: 799.99 }
],
shippingAddress: {
street: '321 Pine St',
city: 'Elsewhere',
state: 'FL',
zipCode: '98765'
},
paymentMethod: 'Bank Transfer',
bankTransactionId: 'BT-9876543210'
}
]);
print('Sample data loaded successfully');
"
echo "MongoDB is running and sample data is loaded."