I'm trying to query a Firestore Document to retrieve a single field after a onCreate function.
import * as functions from 'firebase-functions';
import admin = require('firebase-admin');
admin.initializeApp();
const db = admin.firestore();
exports.logActivities = functions.firestore
.document("AccountLog/{docID}")
.onCreate(async (snap, context) => {
const newValues = snap.get('newBalace');
console.log(newValues);
const query = db.collection('iniAccounts');
const querySnapshot = await query.get();
const initialValues = querySnapshot.docs.map(document => (document.data()));
console.log(initialValues);
});
The collection that i'm querying only has one document with 2 fields. When I execute the code above the "document.data()" retrieves all the fields and values for the document.
[ { cStartingBalance: '288',
cStartingDate: '12/30/2019' } ]
The only field I need is the cStartingBalance. I have tried several solutions but none have retrieved just the cStartingBalance value.
Since the goal is to compare the newValues with the initialValues, is there a different approach that i should be taking? Any assistance would be appreciated.
initialValuesarray... - Doug Stevenson