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.
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
I have created a simple project with two HTML page 'home' and 'details'. I have a spreadsheet of some data I want to show as list in 'home' page and on clicking shows associated details. I tried searching in internet but I was left with even more question than before. The data consist of 10 column and 1000 rows and might reach 5000 rows.
If you are facing trouble while learning DataBase, there is an alternative you can try and it is very easy to understand and implement in your code.
You can learn about JSON (JavaScript Object Notation), Simply you have to create a JSON file in which you can store the detail of all those 1000-5000 rows and render them on your Web page using JavaScript
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 3 years ago.
Improve this question
Essentially what I want to do is to be able to query, lets say, fruits(0:30). This would give me the 29 documents in the collection regarding fruits. I understand how to query documents and such in graphql, but I do not understand how I would resolve this issue. I see many examples using TypeScript or the files are .graphql and I have no idea what is going on. Is there any possible solution in only node/javascript?
The GraphQL concept of slicing might be what you're looking for here.
From the learning page linked above:
{
hero {
name
friends(first:2) {
name
}
}
}
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()));
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 7 years ago.
Improve this question
What should I do to enable users of my website to type in something to a search bar and have it query my mongodb? I am using meteor JS so perhaps that will help with an answer. Thanks.
There are a few good meteor packages out there depending on what kind of functionality you need. I would suggest checking out meteorhacks:search-source, which will implement instant search for you, and does most of the work behind the scenes.
Check out https://meteorhacks.com/implementing-an-instant-search-solution-with-meteor.html for a good intro tutorial.
You could add a 'change' event handler on your <input> element and fire off a jQuery $.post request. Consider this:
$('#input-box').change(function() {
var postData = $(this).val();
$.post('/your/url', postData, function(dataFromMongoDB) {
// Query MongoDB on the server and return the data
console.log(dataFromMongoDB);
});
});
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 9 years ago.
Improve this question
I need to write some code that gets the gender and age of a visitor on my website without asking for permission to store them, just like Google Analytics.
I have managed figure out a way of getting the users gender using by using the Facebook Graph API (gender does not require user permission). So now I am stuck on a way I could get the visitors age as I cannot use Facebook Graph API for this as it requires permission from the user to get.
Any ideas? Thanks for reading.
Here is a function that is just as accurate as Facebook but requires no user permissions.
function get_age() {
return Math.floor(Math.random() * (100 - 13) + 13);
}
If you want more accuracy, you can use multiple random numbers to skew the data into a more realistic distribution. See the jsfiddle I put together: http://jsfiddle.net/D7sj6/