|
1 | 1 | // //practicechartdata db에서 중복된 날짜 제거 |
2 | | -const mongoose = require("mongoose"); |
3 | | -const PracticeChartData = require("../models/PracticeChartData"); // 경로 수정 |
4 | | -require("dotenv").config(); |
5 | | - |
6 | | -async function removeDuplicatePrices() { |
7 | | - await mongoose.connect(process.env.DB_URI); |
8 | | - |
9 | | - const docs = await PracticeChartData.find({}); |
10 | | - |
11 | | - for (const doc of docs) { |
12 | | - const seen = new Map(); // 날짜 -> 첫 price |
13 | | - const uniquePrices = []; |
14 | | - |
15 | | - for (const price of doc.prices) { |
16 | | - if (!seen.has(price.date)) { |
17 | | - seen.set(price.date, true); |
18 | | - uniquePrices.push(price); |
19 | | - } |
20 | | - } |
21 | | - |
22 | | - if (uniquePrices.length !== doc.prices.length) { |
23 | | - console.log( |
24 | | - `[중복 제거] ${doc.stock_code}: ${doc.prices.length} → ${uniquePrices.length}` |
25 | | - ); |
26 | | - doc.prices = uniquePrices; |
27 | | - await doc.save(); |
28 | | - } |
29 | | - } |
30 | | - |
31 | | - await mongoose.disconnect(); |
32 | | - console.log("✅ 중복 제거 완료"); |
33 | | -} |
34 | | - |
35 | | -removeDuplicatePrices().catch((err) => { |
36 | | - console.error("❌ 오류 발생:", err); |
37 | | -}); |
38 | | - |
39 | | -// // 테스트용, 전 종목 직전일 주가정보 업데이트 |
40 | 2 | // const mongoose = require("mongoose"); |
41 | | -// // const { fetchDailyPrice } = require("./fetchStockPrice"); |
| 3 | +// const PracticeChartData = require("../models/PracticeChartData"); // 경로 수정 |
| 4 | +// require("dotenv").config(); |
| 5 | + |
| 6 | +// async function removeDuplicatePrices() { |
| 7 | +// await mongoose.connect(process.env.DB_URI); |
| 8 | + |
| 9 | +// const docs = await PracticeChartData.find({}); |
| 10 | + |
| 11 | +// for (const doc of docs) { |
| 12 | +// const seen = new Map(); // 날짜 -> 첫 price |
| 13 | +// const uniquePrices = []; |
| 14 | + |
| 15 | +// for (const price of doc.prices) { |
| 16 | +// if (!seen.has(price.date)) { |
| 17 | +// seen.set(price.date, true); |
| 18 | +// uniquePrices.push(price); |
| 19 | +// } |
| 20 | +// } |
| 21 | + |
| 22 | +// if (uniquePrices.length !== doc.prices.length) { |
| 23 | +// console.log( |
| 24 | +// `[중복 제거] ${doc.stock_code}: ${doc.prices.length} → ${uniquePrices.length}` |
| 25 | +// ); |
| 26 | +// doc.prices = uniquePrices; |
| 27 | +// await doc.save(); |
| 28 | +// } |
| 29 | +// } |
| 30 | + |
| 31 | +// await mongoose.disconnect(); |
| 32 | +// console.log("✅ 중복 제거 완료"); |
| 33 | +// } |
| 34 | + |
| 35 | +// removeDuplicatePrices().catch((err) => { |
| 36 | +// console.error("❌ 오류 발생:", err); |
| 37 | +// }); |
| 38 | + |
| 39 | +// 테스트용, 전 종목 직전일 주가정보 업데이트 |
| 40 | +// const mongoose = require("mongoose"); |
| 41 | +// require("dotenv").config(); |
42 | 42 |
|
43 | 43 | // const { fetchAllStockPrice } = require("../tasks/dailyStockUpdater"); |
44 | 44 | // async function testInsert() { |
|
0 commit comments