adding loading historical data on server start

This commit is contained in:
sairaj mote 2024-01-11 04:40:23 +05:30
parent 083e8e0d35
commit 0d47ae3efe
2 changed files with 10 additions and 1 deletions

View File

@ -169,6 +169,15 @@ function loadHistoricToDb() {
console.log(err);
})
}
// run loadHistoricToDb() only once when the server starts and no data is present in the database
PriceHistory.countDocuments({}, (err, count) => {
if (err) {
console.log(err);
}
if (count === 0) {
loadHistoricToDb();
}
})
app.get("/price-history", async (req, res) => {
try {

2
index.min.js vendored

File diff suppressed because one or more lines are too long