0

How i can get all data from hotel to cant print the data to console, to be able to print in this way the data

"nombre, rfc, infGen,ubicacion"

My database

4
  • The answer to your question is in the documentation for firebase. firebase.database().ref('Hotel').once('value').then(function(snapshot){}, function(error){}) Commented Nov 1, 2017 at 1:27
  • i read the documentation, but i cannot undertand how get list of data, and manage the results Commented Nov 1, 2017 at 1:29
  • in the first function, the variable snapshot is your firebase query response. snapshot.val() would give you the object containing the data you are after Commented Nov 1, 2017 at 1:31
  • thanks, i find the solution Commented Nov 1, 2017 at 3:07

2 Answers 2

1

You can also use the Firebase REST API if the realtime reference syntax is throwing you off. Using an AJAX library (I will use axios for the example), you can easily read data from your database.

Below are some examples on how to read data from Firebase.

// This first call will return the root of your database
// By appending the url with '.json', the response will be JSON
axios('https://**your-database-here**.firebaseio.com/.json')
.then(response => {
  // Using .then to access the resolved data from the promise
  // "response" itself is an object, but our data is assigned to the data property
  console.log(response.data);
});

// This call will return a single collection, such as the Hotel collection. 
// Be aware that firebase does not return array, but instead returns an object of key - value pairs
axios('https://**your-database-here**.firebaseio.com/Hotel.json')
.then(response => {
  console.log(response.data);

  var hotel = response.data; // Again, just wait the actual data
  // Will need to loop over object to get nested data here
});

<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
Sign up to request clarification or add additional context in comments.

Comments

0

foreach is the operation that need, this get data one by one

var query = firebase.database().ref("Hotel/"+usuario.uid);
        query.once("value")
          .then(function(snapshot) {
            snapshot.forEach(function(childSnapshot) {
              var hrfc = childSnapshot.val().RFC;
              var hnombre = childSnapshot.val().nombre;
              var hinfo = childSnapshot.val().infoGen;
              var hubic = childSnapshot.val().ubicacion;


          });
        });

}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.