vuejs2google-cloud-firestorevuefire

VueJs, Vuefire, Firestore: How can I filter a synched Firestore document


Using vuefire allows me to set a firestore object on the vue instance and automatically syncs it with Firestore. I ALSO want to filter that for another data point but filtering causes an error.

The code below returns the staff which is desired and working perfectly. The Firebase User (fbUser) returns

WEBPACK_IMPORTED_MODULE_0__services_Firebase.a.collection(...).filter is not a function

and the datapoint is empty in VueTools

firestore() {
    return {
        staff: db.collection('staff').orderBy('lastname'),
        fbUser: db.collection('staff').filter(s => s.email === this.current_user.email)
    }
 },

Solution

  • db.collection doesn't returns directly the result. I don't know the implementation, but I suppose vuefire will create a data field named fbUser and save result in it.

    I think, the best solution is to use computed data like:

    computed: {
        fbUserFiltered () {
            return this.fbUser.filter(s => s.email === this.current_user.email);
        }
    }