-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdate-mongodb.js
More file actions
35 lines (29 loc) · 983 Bytes
/
update-mongodb.js
File metadata and controls
35 lines (29 loc) · 983 Bytes
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
const mongoose = require('mongoose');
const Commit = require('./server/models/Commit');
async function updateMongoDB() {
try {
await mongoose.connect('mongodb://localhost:27017/amz_toy_dbe', {
useNewUrlParser: true,
useUnifiedTopology: true
});
const latestCommits = require('./commits/latest_commits.json');
for (const commit of latestCommits) {
const existingCommit = await Commit.findOne({ commitId: commit.sha });
if (!existingCommit) {
const newCommit = new Commit({
message: commit.commit.message,
author: commit.commit.author.name,
commitId: commit.sha
});
await newCommit.save();
console.log(`Commit saved to MongoDB: ${commit.sha}`);
}
}
console.log('MongoDB update complete');
} catch (error) {
console.error('Error updating MongoDB:', error);
} finally {
mongoose.disconnect();
}
}
updateMongoDB();