Closed kiptoomm closed 3 years ago
I tested this in the latest version of fireway
and it works. Two potential issues with your migration:
fireway
, which could be using an older version of firebase-admin
that doesn't have FieldValue.delete()
. Try installing the latest version of fireway
.FieldValue
class. Use that to ensure compatibility (and make your code cleaner). Here's the example that works in my test:module.exports.migrate = async ({ firestore, FieldValue }) => {
await firestore.collection('data').doc('doc').update({
field1: FieldValue.delete()
});
};
If you still have trouble after those suggestions, feel free to comment and I'll reopen the issue.
...could be using an older version of
firebase-admin
that doesn't haveFieldValue.delete()
. Try installing the latest version offireway
.
Gee, I didn't realize how old the version I had before was. I upgraded it to the latest version and, without changing anything else, tested the script again and there was still no change in behavior.
FieldValue.delete()
actually exists though in the rather odd path node_modules/@google-cloud/firestore/types/firestore.d.ts:FirebaseFirestore.FieldValue
. Based on this potentially relevant SO answer, it seems FieldValue
is actually not available in firebase-admin
, which is somewhat confusing. In any case, I'd have expected the interpreter to complain if FieldValue.delete()
was actually missingMigrations are provided the
FieldValue
class. Use that to ensure compatibility (and make your code cleaner)
This is the change that did it! 🎉 🙇
Based on the official docs, I have been trying to implement a migration that removes some deprecated fields in my documents. Here's the error I have consistently faced:
Update() requires either a single JavaScript object or an alternating list of field/value pairs that can be followed by an optional precondition. Value for argument "dataOrField" is not a valid Firestore document. Couldn't serialize object of type "DeleteTransform" (found in field "test1"). Firestore doesn't support JavaScript objects with custom prototypes (i.e. objects that were created via the "new" operator).
Here's the minimal code that reproduces the error (this same code works as expected when run as a script of its own, or when it's executed from a REST endpoint function):
Any ideas on how I can get it working with fireway?
My stack: