Home > Mobile >  Attempting to use equalTo on Firebase Realtime Database query
Attempting to use equalTo on Firebase Realtime Database query

Time:03-05

I have the following node:

attendanceOptions: {
uid1: '[email protected]',
uid2: '[email protected]'
}

I'm trying to return only the key and value where value is equal to. These are my two attempts.

  const getMinistry = await admin.database().ref(`organization/${req.orgId}/attendanceOptions`)
  getMinistry
    .equalTo(req.memberUid)
    .once('value', snapshot => {
      functions.logger.log(snapshot.val())
    });

This returns null I also tried:

  const getMinistry = await admin.database().ref(`organization/${req.orgId}`)
  getMinistry
    .orderByChild('attendanceOptions')
    .equalTo(req.memberUid)
    .once('value', snapshot => {
      const data = snapshot.val();
      functions.logger.log( `this is data: ${data}` )
      return data;
    });

The log is this is data: null

In my rules I have:

"attendanceOptions": {
  ".indexOn": [".value"]
},

What am I doing wrong here?

CodePudding user response:

The correct syntax is:

getMinistry
  .child('attendanceOptions')
  .orderByValue()
  .equalTo(req.memberUid)
  • Related