简体   繁体   中英

Post data in array cloud firestore

Am working on an array to store multiple map location in an array using geopoint . Have a location:geopoint that accepts latitude and longitude, which are stored in an array. 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. 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. 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).
  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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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