Firebase Database: Why Do The Key/ref In My Queried Datasnapshot Refer To Its Parent?
I would like to delete an entry from the realtime database that i looked up through a query but i am getting unexpected results for both the ref and key properties. ref('photos/use
Solution 1:
When you execute a query against the Firebase Database, there will potentially be multiple results. So the snapshot contains a list of those results. Even if there is only a single result, the snapshot will contain a list of one result.
Your code needs to take this list into account, and iterate over snapshot.forEach()
to get the actual matching item:
ref('photos/users/USERID')
.orderByChild('photoname')
.equalTo('photoname i want to look up')
.limitToFirst(1)
.query('once')
.then(snapshot => {
snapshot.forEach(child => {
const entry = child.val();
constref = child.ref;
const key = child.key
});
})
Post a Comment for "Firebase Database: Why Do The Key/ref In My Queried Datasnapshot Refer To Its Parent?"