如何使用react将嵌套数组添加到Firestore数据库中?

时间:2020-07-13 09:14:06

标签: reactjs firebase google-cloud-firestore nested-object

我的反应代码中有一个对象,如下所示。

const [inputs, setInputs] = useState({
        groupName: '',
        groupDescription: '',
        priv: []
    });

将setInputs设置为上述状态后,我将执行以下功能。

    const addDataToFb = () => {
        console.log(inputs)
            firebase.firestore().collection('userGroups').add(inputs)
                .then(() => {
                    alert('Group successfully created')
                    resetButtonHandler();
                })
                .catch((err) => {
                    alert(err)
                })
    }

控制台已记录以下详细信息。 Refer this image.

1 个答案:

答案 0 :(得分:1)

您无法将undefined值提交到图像中显示的{ignoreUndefinedProperties: true},因为在提交时Firestore会引发错误。

您可以通过在初始化Firestore时添加以下属性来关闭此行为:

import logging import boto3 from botocore.exceptions import ClientError def upload_file(file_name, bucket, object_name=None): """Upload a file to an S3 bucket :param file_name: File to upload :param bucket: Bucket to upload to :param object_name: S3 object name. If not specified then file_name is used :return: True if file was uploaded, else False """ # If S3 object_name was not specified, use file_name if object_name is None: object_name = file_name # Upload the file s3_client = boto3.client('s3') try: response = s3_client.upload_file(file_name, bucket, object_name) except ClientError as e: logging.error(e) return False return True