-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinsertData.js
61 lines (54 loc) · 2.24 KB
/
insertData.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
const { MongoClient } = require('mongodb');
async function main() {
const uri = 'mongodb+srv://oQriWvlwHZibxGTx:[email protected]/digitalGarden?retryWrites=true&w=majority';
const client = new MongoClient(uri);
try {
await client.connect();
console.log('Connected to the database');
const database = client.db('your_database_name');
const collection = database.collection('projects');
const sampleData =
[
{
"title": "Personal Portfolio Website",
"summary": "A personal website to showcase my development projects and skills.",
"tech": ["HTML", "CSS", "JavaScript", "React"],
"github": "https://github.com/yourusername/portfolio-website",
"demo": "https://yourusername.github.io",
"images": [
"https://example.com/image-portfolio1.png",
"https://example.com/image-portfolio2.png"
]
},
{
"title": "Task Management App",
"summary": "A to-do list app with custom categories, priorities, and due dates.",
"tech": ["Node.js", "Express", "MongoDB", "Vue.js"],
"github": "https://github.com/yourusername/task-manager",
"demo": "https://taskmanager.example.com",
"images": [
"https://example.com/image-taskmanager1.png",
"https://example.com/image-taskmanager2.png"
]
},
{
"title": "Weather Forecast App",
"summary": "An app that fetches and displays weather data from an external API.",
"tech": ["Python", "Flask", "OpenWeatherMap API"],
"github": "https://github.com/yourusername/weather-app",
"demo": null, // null if no demo is available
"images": [
"https://example.com/image-weatherapp.png"
]
}
]
;
const result = await collection.insertMany(sampleData);
console.log(`${result.insertedCount} documents were inserted`);
} catch (err) {
console.error('An error occurred:', err);
} finally {
await client.close();
}
}
main();