javascript - 如何删除(或添加)作为 Firebase Firestore 云文档一部分的数组内的对象?
问题描述
我在 Firestore 中有一个集合(患者),其中包含多个文档(每个患者),每个文档都有一个自动生成的 ID,在我的 Web 应用程序中我显示了一个特定文档,该文档是我使用角度路由器的 ActivatedRoute 从其 ID 获得的。
在我的服务中,我可以使用以下代码通过 id 访问一个单独的“Patient”:
export class FirebaseService {
private patientCollection: AngularFirestoreCollection<Ipatients>;
constructor(private afs: AngularFirestore) {
this.patientCollection = afs.collection<Ipatients>("Patient", (ref) =>
ref.orderBy("Name")
);
}
public getOnePatient(id: Ipatients): Observable<Ipatients> {
return this.afs.doc<Ipatients>(`Patient/${id}`).valueChanges();
}
这是我的 component.ts,我在 ngOnInit 中请求单个患者(按 id)
constructor(
private fbservice: FirebaseService,
private route: ActivatedRoute
) {
this.route.params.subscribe((params) => {
console.log(params["id"]);
});
}
ngOnInit() {
const idPatient = this.route.snapshot.params.id;
this.fbpatient$ = this.fbservice.getOnePatient(idPatient);
}
在 HTML 中,我只渲染部分患者信息,我渲染的部分是文档中称为会话的数组,这些是我希望用户与之交互的会话,因此我循环遍历患者内部的会话数组和用 ngFor 显示里面的每个对象
这是患者数据的示例:
fbpatient: Ipatients =
{
id: "asdSDWESHGawhadah",
Nombre: "John",
Apellido: "Doe",
Edad: "30",
Telefono: "098849625",
Mutualista: "SMI",
Sesiones: [ // THIS IS THE ARRAY I WANT TO C.R.U.D
{
nombre: "Sesion1",
ordenesEntregadas: 1,
fechaSesion: new Date(2019, 11, 24),
asistencia: "Asistio",
conAviso: null,
datosCompletos: true,
},
{
nombre: "Sesion2",
ordenesEntregadas: 1,
fechaSesion: new Date(2019, 11, 24),
asistencia: "Asistio",
conAviso: null,
datosCompletos: true,
},
],
}
我的问题是如何在患者体内删除(或添加)“会话”,我的服务需要什么代码?我找不到这种情况的任何例子,只有整个文档的 CRUD
解决方案
推荐阅读
- python - Flask - 多客户端上传
- python - 优化和批处理字节文件数据到 keras 模型中
- c# - ASP.NET Core 运行时(动态)配置外部库设置?
- python - tkinter 中的 event.x,event.y 和 event.x_root,event.y_root 有什么区别?
- r - 两个日期期间的部分或全部重叠
- r - 如何从 R 中的两个 df 中获得常见(反之亦然)和不常见的行
- netcdf - 在 netcdf 的特定维度中裁剪/选择许多不连续的像素
- jquery - 带有“显示更多”按钮的 jQuery 多分页系统
- python - 无需重复前缀即可构建 dict 的单行代码
- c - 诅咒:如何显示 wint_t 字符