简体   繁体   中英

Firebase Firestore - committing array objects as separate documents

I am working on a Vue.js application where the idea is to allow coaches to code specific plays for analysis with a ticking clock to set when the action happened in game time.

For example, user clicks 'time on' to start the clock, clicks 'pass', the value is set in the Vuex Store in an array called localStats. So it would look something like the following:

localStats[
    {
        stat: 'Pass',
        matchTime: '00:02'
    },
    {
        stat: 'Dropped Pass',
        matchTime: '00:04'
    }
]

The idea was to store these locally so that:

  1. There could be a feed of all actions that have happened in the match
  2. A user could delete an errant click before submitting to Firestore (ie 'Whoops! that wasn't a pass, it was a dropped ball', delete from feed/localStats, recode play).

Would there be a way to take all individual objects from an array and set all of the array objects as separate documents in Firestore? Or am I going about this all wrong?

I am dumb. forEach. Set it up where when the user indicated the half is over, submit all documents from the half:

const stats = this.$store.state.localStats;
var matchId = this.$route.params.matchId
stats.forEach(function(object){

    db.collection('matches').doc(matchId).collection('stats').add({
        object
    })
})

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