Firebase how to dynamically search for keystrokes under user data

{
    "foo":{
        "uid":{ // user uid
            "push_key_1":{
               "bar":"baz"
            },
            "push_key_2":{
               "bar":"baz"
            }
        }
    }
}

Given the code model above, how do I dynamically search push_key_1or push_key_2in a query?

I have tried:

var searKey = 'push_key_1';

db.ref('foo').orderByKey().equalTo(searKey).once('value')
    .then(function(snap){
        // snap.val() returns null.
    }).catch();

But snap.val()- null. Turns off is orderByKey()intended only for sorting. Is there any way to achieve this?

+4
source share
2 answers

It is much easier than you are trying. When you know the node key you want to download, you don't need a request at all:

db.ref('foo').child(searKey).once('value'....
0
source

, , . , node .

"users_push_keys": {
    "push_key_1": "uid_1",
    "push_key_2": "uid_1"
}

uid, node. , :)

0

Source: https://habr.com/ru/post/1661600/


All Articles