-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinsert_data.js
121 lines (117 loc) · 3.42 KB
/
insert_data.js
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
import mongoose from "mongoose";
import { Service } from "./models/services.js";
const MONGO_URI =
"mongodb+srv://eventorycareers:C%[email protected]/dev?retryWrites=true&w=majority&appName=Eventory"; // Replace with your MongoDB URI
// Connect to MongoDB
mongoose
.connect(MONGO_URI, {
useNewUrlParser: true,
useUnifiedTopology: true,
})
.then(() => console.log("Connected to MongoDB"))
.catch((error) => console.error("Failed to connect to MongoDB:", error));
// Dummy data to insert
const dummyServices = [
{
id: "1",
photo:
"https://d1u34m45xfa3ar.cloudfront.net/Photographers/images/1736350806163-jayesh-jalodara-bWQ6-0c_ZcM-unsplash.jpg",
description: "Service 1 description",
name: "Service 1",
address: "123 Main St",
price: "$100",
type: "Type A",
},
{
id: "2",
photo:
"https://d1u34m45xfa3ar.cloudfront.net/Photographers/images/1736350806163-jayesh-jalodara-bWQ6-0c_ZcM-unsplash.jpg",
description: "Service 2 description",
name: "Service 2",
address: "456 Elm St",
price: "$200",
type: "Type B",
},
{
id: "3",
photo:
"https://d1u34m45xfa3ar.cloudfront.net/Photographers/images/1736350806163-jayesh-jalodara-bWQ6-0c_ZcM-unsplash.jpg",
description: "Service 3 description",
name: "Service 3",
address: "789 Oak St",
price: "$150",
type: "Type C",
},
{
id: "4",
photo:
"https://d1u34m45xfa3ar.cloudfront.net/Photographers/images/1736350806163-jayesh-jalodara-bWQ6-0c_ZcM-unsplash.jpg",
description: "Service 4 description",
name: "Service 4",
address: "321 Maple St",
price: "$250",
type: "Type D",
},
{
id: "5",
photo:
"https://d1u34m45xfa3ar.cloudfront.net/Photographers/images/1736350806163-jayesh-jalodara-bWQ6-0c_ZcM-unsplash.jpg",
description: "Service 5 description",
name: "Service 5",
address: "654 Pine St",
price: "$300",
type: "Type A",
},
{
id: "6",
photo:
"https://d1u34m45xfa3ar.cloudfront.net/Photographers/images/1736350806163-jayesh-jalodara-bWQ6-0c_ZcM-unsplash.jpg",
description: "Service 6 description",
name: "Service 6",
address: "987 Birch St",
price: "$180",
type: "Type B",
},
{
id: "7",
photo:
"https://d1u34m45xfa3ar.cloudfront.net/Photographers/images/1736350806163-jayesh-jalodara-bWQ6-0c_ZcM-unsplash.jpg",
description: "Service 7 description",
name: "Service 7",
address: "159 Willow St",
price: "$400",
type: "Type C",
},
{
id: "8",
photo:
"https://d1u34m45xfa3ar.cloudfront.net/Photographers/images/1736350806163-jayesh-jalodara-bWQ6-0c_ZcM-unsplash.jpg",
description: "Service 8 description",
name: "Service 8",
address: "753 Cedar St",
price: "$220",
type: "Type D",
},
{
id: "9",
photo:
"https://d1u34m45xfa3ar.cloudfront.net/Photographers/images/1736350806163-jayesh-jalodara-bWQ6-0c_ZcM-unsplash.jpg",
description: "Service 9 description",
name: "Service 9",
address: "951 Spruce St",
price: "$500",
type: "Type A",
},
];
// Insert dummy data
const insertDummyData = async () => {
try {
await Service.insertMany(dummyServices);
console.log("Dummy data inserted successfully!");
mongoose.connection.close();
} catch (error) {
console.error("Error inserting dummy data:", error);
mongoose.connection.close();
}
};
insertDummyData();