Currently experiencing confusion with my query to the Firebase database. As a beginner, I opted for a "simple tutorial" to grasp data reading. Creating a JSON object was successful and brought me joy. However, attempting to read data has become frustrating. My goal was to retrieve a single "record" where the email address matched a specific email. These email addresses are expected to be unique in a user database. Once I accessed the user, I aimed to utilize their UID generated by push(); for further actions. Since this is a demo and security is not a concern at this stage, the default read and write permissions of a newly created Firebase database apply - granting full access from anywhere to anyone.
This snippet represents the code of the demonstration site used to test functionality:
<body>
<h1>retrieve data</h1>
<div id="aaa" style="margin:20px;padding:20px;border-radius:30px;background-color:#6666FF;float:left">USERADD</div>
<div style="clear:both"></div>
<pre id="rawdata"></pre>
</body>
The above is the successful demo code that operated as intended.
var demofbdb = new Firebase("https://examples-sql-queries.firebaseio.com/user");
demofbdb
.startAt('<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="9ffef1fef1ebdff9f6edfafdfeecfab1fcf0f2">[email protected]</a>')
.endAt('<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="b2d3dcd3dcc6f2d4dbc0d7d0d3c1d79cd1dddf">[email protected]</a>')
.once('value', function show(record) {
$('#rawdata').text(JSON.stringify(record.val(), null, 4));
});
The following code is my own implementation which returns null without a clear explanation:
var demofbdb = new Firebase("https://<my-firebase-database>.firebaseio.com/Users");
demofbdb
.startAt('<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="5f3b3a3230713b3a3b3a323030311f3b3a2c3e2b3e31362c2b3a3171302d38">[email protected]</a>')
.endAt('<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="086c6d6567266c6d6c6d65676766486c6d7b697c6966617b7c6d6626677a6f">[email protected]</a>')
.once('value', function show(record) {
$('#rawdata').text(JSON.stringify(record.val(), null, 4));
});
This structure exemplifies the contents found within /Users:
"-JlyxV5xvQFLybevk9kD" : {
// User details here
},
"-JlyxSJ8MciBNxguT415" : {
// User details here
}
To clarify, the UIDs are directly beneath Users. Expanding on the UIDs reveals detailed information about each user.
The desired outcome of my query is to obtain the JSON object of the user identified by the first name "Demo" and last name "De Demoon".
Your assistance is greatly appreciated.
PS: While I have more experience with SQL databases than noSQL, circumstances have led me to explore the latter option. I believe noSQL databases prove advantageous when dealing with precomputed data that requires consistent joins. Storing these results in a noSQL database enhances lookup speed by minimizing unnecessary loads and grouping frequently requested datasets together. Feel free to correct any misconceptions in my understanding.