简体   繁体   English

将数据发布到阵列云Firestore中

[英]Post data in array cloud firestore

Am working on an array to store multiple map location in an array using geopoint . 我正在处理一个数组,以使用geopoint在数组中存储多个地图位置。 Have a location:geopoint that accepts latitude and longitude, which are stored in an array. 有一个接受纬度和经度的location:geopoint ,它们存储在数组中。 Cloud firestore only has set for creating new document update update existing document and add which have tried to add new geopoint to the array but it doesn't work. Cloud Firestore仅set用于创建新文档的update更新现有文档并add已尝试将新的Geopoint添加到阵列中的文档,但这是行不通的。 How can I add new location while maintaining the previous data? 如何在维持先前数据的同时添加新位置?

Cloud Firestore doesn't currently have an "append an element to an array" kind of operation. Cloud Firestore当前没有“将元素添加到数组”类型的操作。 For now, your best options are to either: 目前,您最好的选择是:

  1. Override the existing array with a new array that contains all of the old data as before, plus the new data 用新数组覆盖现有数组,该数组包含以前的所有旧数据以及新数据
  2. Add this new geopoint into a map field instead (The things that look like little JSON-y objects). 而是将这个新的地理位置添加到地图字段中(看起来像小的JSON-y对象)。
  3. Add every new geopoint as a new document in a subcollection. 将每个新的地理位置添加为子集合中的新文档。

Your implementation might depend on how many of these different geopoints you're planning on creating, and how you plan on querying them. 您的实现可能取决于您计划创建多少个不同的地理位置,以及计划如何查询它们。 If you're creating only a handful and want to get all of them back when you're grabbing the associated document, I'd go with one of the first two options. 如果您只创建少数几个文件,并且想在获取关联文档时将所有文件都找回,那么我将使用前两个选项之一。 If you're planning on creating lots of geopoints and, say, want to only grab the 3 most recent, I'd go with the third option. 如果您打算创建大量的地理点,并且想只获取最近的三个,那么我会选择第三个选项。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM