let askTime = Math.floor(((1732217967809 - 1732174653061) / (1000 * 60)) % 60)
console.log((1732217967809 - 1732174653061))
console.log(askTime)
43314748
1
如何计算以秒为单位的时差?这个单位来自哪里?
let askTime = Math.floor(((1732217967809 - 1732174653061) / (1000 * 60)) % 60)
console.log((1732217967809 - 1732174653061))
console.log(askTime)
43314748
1
如何计算以秒为单位的时差?这个单位来自哪里?
let data = 3200
let start = 0, end = 500;
for (let i = 0; i < Math.ceil(data.length / 500); i++){
await addDb(data.slice(start,end))
start += 500
end += 500
}
async function addDb(data){
console.log('addDB', data.length)
for await (const coin of data) {
await mongoCollection.replaceOne({
exchange: coin.exchange,
symbol: coin.symbol
}, coin, {upsert: true});
}
}
如何并行运行多个 addDB 函数,以便每个函数写入部分行?使用await,它会一项一项地运行,如果没有await,它不会等待条目,代码会继续工作。
const mongoClient = new MongoClient("mongodb://localhost:27017/");
await mongoClient.connect();
const mongoCollection = mongoClient.db(DB).collection(COLLECTION);
let coins = []
//получение данных
coins.push(coin)
async function addBD(){
console.log(coins.length)
coins = removeDuplicates(coins)
console.log("Без дубликатов ", coins.length)
for (const coin of coins){
await mongoCollection.replaceOne({ exchange: coin.exchange,
symbol: coin.symbol }, coin, {upsert: true});
}
coins = []
console.log(coins.length)
}
setInterval(()=>{
addBD()
}, 5000)
如何让函数在循环完成后运行?不使用间隔。
async function addBD(){
console.log(coins.length)
coins = removeDuplicates(coins)
console.log("Без дубликатов ", coins.length)
for (const coin of coins){
await mongoCollection.replaceOne({ exchange: coin.exchange, symbol: coin.symbol }, coin, {upsert: true});
}
coins = []
console.log(coins.length)
addBD()
}
我这样做了,但出现错误“超出最大调用堆栈大小”