Firebase - data structure problem for retrieving an object from a nested structure

Firebase is a data structure problem for retrieving an object from a nested structure.

I want to find the uid and then check if the key is jobId. I have designated accordingly below.

I am using typescript and angular2 with firebase.

This is my current attempt, which returns "null":

var jobId = "-K5fIAiuHM-4xeEQJiIS"; var uid = "3f61ae7a-99a1-4cbf-9c8e-00b2249956a7"; var userRef = this.refApp.child('key').child(uid); var query = userRef.child('jobId').child(jobId); query.on('value', (snap) => { //This returns null var response = snap.val(); }); 

This is my database structure:

enter image description here

0
source share
1 answer

Your structure /applications/$userId/$jobId . Use these keys to get to your data.

Jsbin demo

 var jobId = "-K5fIAiuHM-4xeEQJiIS"; var uid = "3f61ae7a-99a1-4cbf-9c8e-00b2249956a7"; var refApp = new Firebase('<my-firebase-app>/applications'); var jobRef = refApp.child(uid).child(jobId); jobRef.on('value', (snap) => console.log(snap.val())); 

You are currently using the "key" , which I assume is used in my previous demo. This is just for the show, not for your actual decision. Consider the data structure when reading sample code, as it may change.

+1
source

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


All Articles