Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 4 years ago.
Improve this question
I have this saved in the database, but I can't find the correct line to console log it.
This is the last thing I tried and still not working:
var linesRef = database.ref("/lines");
console.log(
linesRef
.child("L1")
.val().eventattr
);
There are two ways to fetch data from firebase realtime database.
Either you can set a listener, which will automatically sync the data whenever there is a change in the database or you can do one time fetch
in your particular case (to fetch it one time)
you can do
const linesRef = firebase.database().ref("/lines");
linesRef.once("value")
.then(response => console.log(response.val()));
Related
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 3 days ago.
Improve this question
I am trying to retrieve the most recent message in a chat room and I am using React Native. I have stored all the chat messages in the chat state, however, my current code only returns the second to last message. Can anyone assist me in retrieving the latest message in the room?
const GetLastMessage = chat.length > 0 ? chat[chat.length - 1] : "New Message";
I think the reason for this is its retrieving second last msg is your component state is not updated yet and you are already getting that msg.Make sure a point where you are getting updated state and then retrieve a last msg.
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 2 years ago.
Improve this question
I am currently working on a telegram bot, and I want to add a function that can search Wikipedia, and I want to know how to get the 'extract' part without knowing the pageid from this wiki API that I fetch from URL?
For example this one: https://en.wikipedia.org/w/api.php?format=json&action=query&prop=extracts&exintro&explaintext&redirects=1&titles=wiki&utf8
Object.keys(data.query.pages).map(pageId => data.query.pages[pageId]).map(page=>page.extract)
where data is the json you got
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 4 years ago.
Improve this question
This is what my database looks like:
My question is how to I decrement the value of FIELD11 i.e. "4" in my realtime database in Firebase using javascript, everytime I click on DECREMENT Button on my html page it should decrement this value and get updated in realtime database. Thank You
I recommend you use a Firebase transaction.
When working with data that could be corrupted by concurrent modifications, such as incremental counters, you can use a transaction operation.
Example:
https://firebase.google.com/docs/database/web/read-and-write#save_data_as_transactions
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
In the above i attached my database image (front-end). i want to fetch those data as arrays in javascript also need to show it by using documet.write() method.
Thank you in advance.
You provided so little context so I'm gonna make some assumptions on my side.
First I'd like to assume you have to the fetch api. We'll be using that to fetch the data, I'm gonna assume too that you have access to ES6 features and are familiar with promises. And finally, I'm assuming that the data returned is in JSON format.
Here's the solution:
window.fetch('<insert-url-here>')
.then(response => reponse.json())
.then(data => data.forEach(d => document.write(d));
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
I have a Firebase database like shown in the image.
I want to get all the data highlighted in GREEN. But I don't know keys highlighted in RED.
What should be the JavaScript Code for this?
Thanks in advance.
This would log all phone numbers:
var usersRef = firebase.database().ref("users");
usersRef.on("child_added", function(snapshot) {
console.log(snapshot.child("phoneno").val());
});
Note that the Firebase documentation and Codelab cover this and a lot more. I highly recommend you spend some time on those, to become more familiar with Firebase.
If you want to print all phone numbers once, you can do so with:
var usersRef = firebase.database().ref("users");
usersRef.once("value", function(snapshot) {
snapshot.forEach(function(userSnapshot) {
console.log(userSnapshot.child("phoneno").val());
});
});
This specific case is covered in the documentation on listening for value events on a collection of data.