How to use the @google-cloud/firestore.QuerySnapshot function in @google-cloud/firestore

To help you get started, we’ve selected a few @google-cloud/firestore examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github 1amageek / pring-admin.ts / lib / dataSource.js View on Github external
async _operate(snapshot, isFirst) {
        let changes = [];
        if (snapshot instanceof FirebaseFirestore.QuerySnapshot) {
            changes = snapshot.docChanges;
        }
        else {
            changes = snapshot.docChanges();
        }
        changes.forEach(async (change) => {
            const id = change.doc.id;
            switch (change.type) {
                case 'added': {
                    const document = await this._get(change.doc.id, change.doc.data());
                    this.documents.push(document);
                    this.documents = this.documents.sort(this.option.sortBlock);
                    if (!isFirst) {
                        const IDs = this.documents.map(doc => doc.id);
                        if (IDs.includes(id)) {
                            const index = IDs.indexOf(id);