附加到 Firestore 中的 arary 字段 [英] Append to an arary field in Firestore

查看:18
本文介绍了附加到 Firestore 中的 arary 字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 FirebaseVuejs 创建一个数据库元素,其中包含对象数组.

I'm using Firebase and Vuejs to create an database element, which has object array inside.

这就是字段的样子,我想通过表单将任务作为数组添加到moreTasks"中.

That's how the field looks, and I want to add tasks through the form into the 'moreTasks' as an array.

我尝试使用它,但它只是在数据库中创建新实体.

I tried using this, but it just creates new entity in the database.

db.collection('Tasks').add({
    tasker: this.tasker.taskerName
})

我也尝试检查 API,但我无法理解引用,因为我使用不同的方法来实现该目标.

I also tried checking API but I couldnt understand the refs, because I was using different methods to achieve that goal.

creatTask() {
  db.collection('Tasks').add({
    task_id: this.task_id,
    name: this.name,

解决这个问题的正确方法是什么?

What would be correct way to approach this problem?

推荐答案

您可以使用 FieldValue.arrayUnion()文档.例如:

You can append an item to an array using FieldValue.arrayUnion() as described in the documentation. For example:

// Atomically add a new region to the "regions" array field.
washingtonRef.update({
    regions: firebase.firestore.FieldValue.arrayUnion("greater_virginia")
});

这篇关于附加到 Firestore 中的 arary 字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆