Guest User

Untitled

a guest
Oct 19th, 2017
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.14 KB | None | 0 0
  1. const firestore = firebase.firestore();
  2. const documentRef = firestore.collection("forms");
  3.  
  4. function saveFormToFirestore(name, company, email, phone, message) {
  5. documentRef.doc(name).set({
  6. name: name,
  7. company: company,
  8. email: email,
  9. phone: phone,
  10. message: message
  11. }).then(function () {
  12. console.log("Added document to collection");
  13. }).catch(function (error) {
  14. console.error("Error while adding document: ", error);
  15. });
  16. }
  17.  
  18. document.getElementById("queryFirestore").addEventListener('click', function (e) {
  19. var nameToQuery = getInputVal('nameToQuery');
  20. documentRef.doc(nameToQuery).get()
  21. .then(function (doc) {
  22. if (doc.exists) {
  23. document.getElementById('firestoreQueryResult').textContent = JSON.stringify(doc.data());
  24. } else {
  25. document.getElementById('firestoreQueryResult').textContent = "No document found for that name";
  26. }
  27.  
  28. document.getElementById('nameToQuery').textContent = "";
  29. }).catch(function (error) {
  30. console.error("Error while getting document: ", error);
  31. });
  32. });
Add Comment
Please, Sign In to add comment