【发布时间】:2025-11-26 18:20:04
【问题描述】:
我想获得充满多张地图的Question Array。
这是我的 Firebase 结构:Firebase structure
然后我想用shuffle 函数对其进行洗牌,然后在我的firestore中更新它。
exports.shuffleSet = functions.firestore
.document('duell/{duell_id}')
.onCreate((snap, context) => {
const data = snap.data();
const questionsArr = data.set.question;
console.log(questionsArr);
const shuffle = (array) => {
var currentIndex = array.length, randomIndex;
while (0 !== currentIndex) {
randomIndex = Math.floor(Math.random() * currentIndex);
currentIndex--;
[array[currentIndex], array[randomIndex]] = [
array[randomIndex], array[currentIndex]];
}
console.log("Geshuffled: " + array);
return array;
}
return questionsArr.update(shuffle(questionsArr));
});
我的日志中总是有 TypeError: questionsArr.update is not a function 和 Function execution took 22 ms, finished with status: 'error'。
我做错了什么?
【问题讨论】:
-
您的 questionsArr 似乎是一个对象数组。我认为 js 数组没有可用的“更新”方法。我认为您将该数组视为 Firestore 文档引用?
标签: node.js firebase google-cloud-firestore google-cloud-functions