Reputation: 191
Im getting this error
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`.
in my firebase javascript function and I have no idea how to solve it . I found out that in typescript this error happens . But what does this error means in javascript ?
This is my function
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));
The line is the await deleteQuery...
The deleteQuery functions looks like this
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);
});
}
Upvotes: 5
Views: 4573
Reputation: 1
I used a filter to achieve this. I had no field as 'discount' in firestore documents
const activeSubscriptionsSnapshot = await db.collection("subscriptions");
.where("status", "==", "ACTIVE")
.get();
const subscriptionsWithoutDiscount = activeSubscriptionsSnapshot.docs
.filter((doc) => !("discount" in doc.data()));`
Upvotes: 0
Reputation: 801
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
.
This means that you have an ‘undefined’ value in your list. Firebase does not support undefined values in your list, check your list and see if something is undefined
. You can avoid this by using ignoreUndefinedProperties
. Here is an example of how you can achieve this:
import * as firestore from "firebase-admin";
Then just need to have something like this:
const db = firestore.firestore();
db.settings({ ignoreUndefinedProperties: true })
Upvotes: 13