我收到这个错误
error is here: Error: Value for argument "value" is not a valid query constraint. Cannot use "undefined" as a Firestore value. If you want to ignore undefined values, enable `ignoreUndefinedProperties`.
在我的firebasejavascript函数中,我不知道如何解决它。我发现在打字脚本中会出现这种错误。但是这个错误在javascript中意味着什么?
这是我的功能
import * as functions from "firebase-functions";
import admin from "firebase-admin";
import {
deleteCollection,
deleteQuery,
deleteUserData,
} from "../utils/deletion";
export default functions.firestore
.document("deletions/{userUid}")
.onDelete(async (snap, context) => {
const db = admin.firestore();
const { userUid } = context.params;
const { uid } = userUid;
//dont forget to delete storage files
try {
await db.doc(`deletions/${userUid}/meinprofilsettings/${uid}`).delete();
await deleteQuery(db, db.collection(`deletions/${userUid}/videos`).where("uid", "==", uid));
行是等待deleteQuery。。。
deleteQuery函数看起来像这个
async function deleteQuery(db, query, batchSize = 100) {
const q = query.limit(batchSize);
return new Promise((resolve, reject) => {
deleteQueryBatch(db, q, resolve).catch(reject);
});
}
async function deleteQueryBatch(db, query, resolve) {
const snapshot = await query.get();
const batchSize = snapshot.size;
if (batchSize === 0) {
// When there are no documents left, we are done
resolve();
return;
}
// Delete documents in a batch
const batch = db.batch();
snapshot.docs.forEach((doc) => {
batch.delete(doc.ref);
});
await batch.commit();
// Recurse on the next process tick, to avoid
// exploding the stack.
process.nextTick(() => {
deleteQueryBatch(db, query, resolve);
});
}
错误:参数的值"值";不是有效的查询约束。不能使用";未定义的";作为Firestore值。如果你想忽略未定义的值,启用
ignoreUndefinedProperties
。
这意味着您的列表中有一个"未定义"值。Firebase不支持您的列表中的未定义值,请检查您的列表,看看是否有undefined
。您可以通过使用ignoreUndefinedProperties
来避免这种情况。以下是如何实现这一目标的示例:
import * as firestore from "firebase-admin";
然后只需要有这样的东西:
const db = firestore.firestore();
db.settings({ ignoreUndefinedProperties: true })