将数据数组临时存储在Firestore中 [英] Temporarily store array of data in Firestore

查看:78
本文介绍了将数据数组临时存储在Firestore中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此问题与我需要使用Firebase Cloud Function通过解析来解析数组中的URL.与其在客户端上遍历URL(可能在此数组中可能包含数百个项目)并向该函数发出单独的请求,不如将整个数组存储在Firestore中,将集合的ID传递给该函数,抓取服务器上的阵列,进行遍历并执行一些操作,然后使用新的ID将其保存回Firestore并使用该ID响应客户端,以便其可以使用/销毁,或者仅响应新的变异数组(不确定我要使用哪一个).

I have a collection of urls in an array that I need to parse through using a Firebase Cloud Function. Instead of iterating through the URL's on the client (I could potentially have hundreds of items in this array) and making individual requests to the function, I'd rather store the entire array in Firestore, pass the ID of the collection to the function, grab the array on the server, iterate through it and perform some operations, and then either save it back to Firestore with a new ID and respond back to the client with that ID so it can consume/destroy, or just respond with an newly mutated array (not sure which one I'd like to use yet).

似乎没有一种首选"的方式将阵列存储在Firebase中,因为通常认为它是邪恶的,但是,如果我不打算长时间保留数据该怎么办?

There doesn't seem to be a "preferred" way to store arrays with Firebase since it's generally considered evil, however, what if I don't plan to keep the data around for very long?

推荐答案

我建议将数组数据写为类似Java的列表:

I would suggest writing array data as a list like this Java:

myDoc.put("urls", Arrays.asList("url1", "url2", "url2"));

这将导致

urls
   0: "url1"
   1: "url2"
   2: "url3"

这篇关于将数据数组临时存储在Firestore中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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