JavaScript
DB

firebase 에러

el

elecball_
답변 대기중
80 XP

이 오류가 왜 발생하는지 궁금합니다.
코드 :

import 'firebase-admin/firestore';
import { cert, initializeApp } from 'firebase-admin/app';
import { getFirestore } from 'firebase-admin/firestore';

import { WebSocket, WebSocketServer } from 'ws';
import express from 'express';

const vol = 0.1;
const min = 1 / (1 + vol), max = 1 + vol;

const firebaseApp = initializeApp({
  credential: cert("./serviceAccount.json"),
  databaseURL: "https://stock-testify.firebaseio.com"
}, "admin_" + (Date.now().toString(32)));

const db = getFirestore(firebaseApp);



const wss = new WebSocketServer({ port: 8080 });

/**
 * @type WebSocket[]
 */
let wsArr = [];

wss.on('connection', function connection(ws) {
  const index = `${new Date().getTime()}${Math.random()}`;
  wsArr.push(ws);
  ws.on('error', console.error);

  ws.on('message', function message(data) {
    console.log('received: %s', data);
  });

  ws.on('close', () => {
    console.log('closed');
    wsArr = wsArr.filter(w => w.ws != ws);
  })
});

updateStocks();

function updateStocks() {
  setTimeout(() => {
    // console.log(new Date());
    db.collection('stocks').get()
    .then(q => {
      q.docs.forEach(async (doc) => {
        const priceList = doc.data().priceList ?? [];
        const date = new Date();
        const newPrice = {
          value: Math.round((priceList.length > 0 ? priceList[priceList.length - 1].value
            * (Math.random() * (max - min) + min) * (Math.random() * (max - min) + min) : 1000) * 100) / 100, 
          time: date
        };
        priceList.unshift(newPrice);
        doc.ref.update({ priceList: priceList });

        wsArr.forEach(ws => ws.send(`${doc.id}/${newPrice.value}/${date.getTime()}`));
      });
    });
    updateStocks();
  }, 60000 - (new Date().getSeconds() * 1000 + new Date().getMilliseconds()))
}
```![image.png](https://cdn.discordapp.com/attachments/1171788935886815252/1171788936025219072/image.png?ex=655df47d&is=654b7f7d&hm=aec3bf97b54a4b98d3d03d3cf8417b8e62823711b138d7242d7b41452bce7e2e&)

불러오는 중...