Firestoreドキュメントからフィールドを削除しようとしていますが成功しません。
表示されるエラーメッセージを検索しましたが、いくつかのページで、すでに実行しているものへのリンクを見つけることができます。これは単純なことだと思いますが、今は途方に暮れています。
const Firestore = require('@google-cloud/firestore');
const admin = require('firebase-admin');
const FieldValue = admin.firestore.FieldValue;
const firestore = new Firestore({
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
});
const settings = {timestampsInSnapshots: true};
firestore.settings(settings);
var updateDoc = firestore.collection('XXXXXXXX').doc('XXXXXXX').update({
fieldToBeDeleted: FieldValue.delete()
});
フィールドが削除されることを期待していますが、代わりに次のエラーメッセージが表示されます。
Error: Update() requires either a single JavaScript object or an alternating list of field/value pairs that can be followed by an optional precondition. Argument "dataOrField" is not a valid Document. Couldn't serialize object of type "DeleteTransform". Firestore doesn't support JavaScript objects with custom prototypes (i.e. objects that were created via the 'new' operator).
at WriteBatch.update (XXXXXXXXXX\node_modules\@google-cloud\firestore\build\src\write-batch.js:359:23)
at DocumentReference.update (XXXXXXXXXX\node_modules\@google-cloud\firestore\build\src\reference.js:387:14)
at Object.<anonymous> (XXXXXXXXXX)
at Module._compile (module.js:652:30)
at Object.Module._extensions..js (module.js:663:10)
at Module.load (module.js:565:32)
at tryModuleLoad (module.js:505:12)
at Function.Module._load (module.js:497:3)
at Function.Module.runMain (module.js:693:10)
at startup (bootstrap_node.js:191:16)
どうやら、CloudSDKとFirebaseAdmin SDK(Cloud SDKをラップする)の間でシンボルを混在させることはできません。Firebaseは独自のシンボルをエクスポートしますが、CloudSDKに直接送信される呼び出しでは使用できません。発信者はどちらか一方を使用する必要がありますが、両方を同時に使用することはできません。
編集:
これは、Firebase AdminSDKを使用せずにCloudSDKのみを使用して機能するようになったコードです。
const Firestore = require('@google-cloud/firestore');
const firestore = new Firestore({
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
});
const settings = {timestampsInSnapshots: true};
firestore.settings(settings);
var updateDoc = firestore.collection('XXXXXXXX').doc('XXXXXXX').update({
fieldToBeDeleted: Firestore.FieldValue.delete()
});
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加