早上好,
我尝试从这个类中添加一个新创建的对象:
export class Sponsor implements ISponsor {
title: string;
description?: string;
creation: ICreation;
constructor(title: string, description: string, author: string) {
this.title = title;
this.description = description;
this.creation = new Creation(author);
}
}
Run Code Online (Sandbox Code Playgroud)
在我的服务中,create函数看起来像:
createSponsor(sponsor) {
sponsor.id = this.afs.createId();
return this.collection.doc(sponsor.id).set(sponsor);
}
Run Code Online (Sandbox Code Playgroud)
当我这样尝试时,我收到以下错误:
FirebaseError:[code = invalid-argument]:函数DocumentReference.set()使用无效数据调用.数据必须是一个对象,但它是:一个自定义的赞助商对象
我该如何解决这个问题?
谁能告诉我,以下错误消息试图告诉我什么?
致命错误:消息为“键写入”的未捕获异常'InvalidArgumentException'在提供的数组中不存在。在/vendor/google/cloud/Core/src/ArrayTrait.php:38中
Stack trace:
#0 /vendor/google/cloud/Firestore/src/Connection/Grpc.php(127): Google\Cloud\Firestore\Connection\Grpc->pluck('writes', Array)
#1 /vendor/google/cloud/Firestore/src/WriteBatch.php(381): Google\Cloud\Firestore\Connection\Grpc->commit(Array)
#2 import.php(45): Google\Cloud\Firestore\WriteBatch->commit()
#3 {main} thrown in /vendor/google/cloud/Core/src/ArrayTrait.php on line 38
Run Code Online (Sandbox Code Playgroud)
我的代码如下:
$batch = $project->db->batch();
foreach($memberList as $member){
$addedDocRef = $collection->newDocument();
$data["id"] = $addedDocRef->id();
$data["creation"] = $this->generateCreation();
$data["publication"] = $this->generatePublication();
$batch->create($addedDocRef, $data);
}
$batch->commit();
Run Code Online (Sandbox Code Playgroud)