title: How to make functions work with Firestore?
body: <p>functions/index.js:</p>
  
  <pre><code>const functions = require('firebase-functions')
  const admin = require('firebase-admin')
  admin.initializeApp(functions.config().firebase)
  const db = admin.database().ref()
  exports.app = functions.https.onRequest((req, res) =&gt; {
    // do whatever here...
    db.child('something').once('value').then(snap =&gt; console.log(snap.key))
  })
  </code></pre>
  
  <p>Above works for Firebase.</p>
  
  <p>I'm interested in making <a href="https://firebase.google.com/docs/firestore/query-data/get-data" rel="noreferrer">this</a> example work from functions. Something like this but working:</p>
  
  <pre><code>const functions = require('firebase-functions')
  const admin = require('firebase-admin')
  admin.initializeApp(functions.config().firebase)
  const db = admin.database().ref()
  
  exports.request = functions.https.onRequest((req, res) =&gt; {
  
    let docRef = db.collection("cities").doc("SF")      
    docRef.get().then(doc =&gt; {
        if (doc.exists) console.log("Document data:", doc.data())
        else console.log("No such document!")
    }).catch(error =&gt; {
        console.log("Error getting document:", error)
    })
  
  })
  </code></pre>