0

Here's the structure of the current database, unfortunately reordering is not an option. database structure

I need to get all the items under the particular user, (5ef124...) but I don't have the uid (5ef124...). I do however have everything marked in green, and I see that the uid is saved under each key. Another issue is that not all records are complete like the one below. There are some that are empty, as in only the parent level key is there.

I have tried to replicate these answers but it's I'm not getting anything back (I'm not getting errors, just no data).

Firebase search by child value? #265

Firebase: Get the parent of a snapshot.

Here's what my broken code looks like, based on link #1:

$rootScope.secondFirebase.refs.vms = $rootScope.secondFirebase.db
    .ref('/users')
    .orderByChild('targetId')
    .equalTo('somehardcodedtargetid')
    .on('value', function(snapshot) {
        //snapshot would have list of NODES that satisfies the condition
        console.log(snapshot.val());
        console.log('-----------');

        //go through each item found and print out the emails
        snapshot.forEach(function(childSnapshot) {
            var key = childSnapshot.key;
            var childData = childSnapshot.val();

            //this will be the actual data value found
            console.log(childData);
        });
    });

Thank you in advance for taking the time to help out.

Edit: please note in the screenshot, only 1 level is unknown. The db/users/5ef124... is the expanded key. It's not db/users/5ef124.../5ef124, but rather db/users/5ef124.../known key.. Or in other words: db/users/[unknown]/[known]. I hope this clarifies it a bit.

Vee
  • 25
  • 5
  • 1
    There is no way to query across two unknown levels in Firebase Realtime Database. If you want to query this data, it'll have to be a flat list with the `targetId` at a known/fixed path under each child node. See https://stackoverflow.com/questions/27207059/firebase-query-double-nested – Frank van Puffelen Jul 29 '20 at 02:21
  • Only 1 level is unknown, the (5ef124...etc). I have the children, (1b8fe..., 1d8fe..., 3f8d420.... etc). – Vee Jul 29 '20 at 02:57
  • 1
    You can search for a nested child with `.ref('/users').orderByChild('1b8fe...,/targetId').equalTo('somehardcodedtargetid')` in that case. But check this answer linked from the other one on why this won't work at scale: https://stackoverflow.com/questions/40656589/firebase-query-if-child-of-child-contains-a-value – Frank van Puffelen Jul 29 '20 at 03:33

0 Answers0