I'm currently attempting to retrieve a value from a specific location in my database, add 1 to it, and then update it back. However, I keep encountering various errors, with the most recent being:
TypeError: Cannot read property 'update' of undefined
at admin.database.ref.once.then (/user_code/lib/index.js:22:25)
I'm unsure as to why it's interpreting it as a property when I thought it was a method. The entirety of my method looks like this:
admin.database().ref('users/' + senderId + '/contacts/' + recipientId)
.once('value').then((contactSnapshot) => {
var mContact = contactSnapshot.val()
let unread = mContact['unread']
console.log('contact name is ' + mContact['user_name'] + ' unread count is ' + unread)
unread++
var contactReference = mContact.ref
contactReference.update({'unread' : unread})
})
My console log displays the contact name and unread count perfectly fine. I admittedly struggle with JavaScript (which this actually is TypeScript), and I plan on addressing that. Any assistance would be greatly appreciated.