title: How to query a Firestore database from a web app outside of the same firebase project
body: <h2>Problem</h2>
  
  <p>I am building a website for a mobile app, App A. I am using firebase to host my website. The website is associated with the same firebase project as App A. Another mobile app I already developed, App B, has a firestore database that I want to be used as a 'news' datasource for App A's website. App B's database is in a different firebase project than the website of App A. I am unable to bridge the connection between app A's website and App B's database.</p>
  
  <h2>AC</h2>
  
  <p>Using firebase, successfully query data from App B's database from the website of App A.</p>
  
  <p>Use firebase environment configuration variables to store private credentials of App B's database. </p>
  
  <h2>Setup</h2>
  
  <p>Developer mode enabled inside the database of App B (Allow everything).</p>
  
  <h3>Web App A start file...</h3>
  
  <pre><code>    functions = require("firebase-functions");
      const firebase = require("firebase-admin");
      downloadNews = require("./db/news/downloadLatestNews");
      transporter = require("./middleware/transport");
      const appA = firebase.initializeApp();
      appADatabase = appA.firestore();
      appADatabase.settings({timestampsInSnapshots:true});
  
      const appB = firebase.initializeApp({
          credential: firebase.credential.cert({
                 projectId: functions.config().appB.project_id,
                 clientEmail: functions.config().appB.client_email,
                  privateKey: functions.config().appB.private_key.replace(/\\n/g, '\n')
            }),
            databaseURL: functions.config().appB.database_url
         }, "AppB");
     appBDatabase = firebase.firestore(appB);
     appBDatabase.settings({timestampsInSnapshots:true});
  </code></pre>
  
  <h3>Module inside Web App A to query from App B's database...</h3>
  
  <p>This function is invoked each time a user makes a request to the '/news' route of Web App A.</p>
  
  <pre><code>const Post = require("../../models/post");
  
  exports.downloadRecent = function() {
    var ref = appBDatabase.collection("users").doc(functions.config().appB.user_id).collection("post_storage");
    ref = ref.where('is_public', '==', true);
    ref = ref.limit(16);
    console.log(ref);
  
    return ref.get().then(snapshot =&gt; {
      if (!snapshot.exists) {
          console.log("No documents exist for userID: " + functions.config().appB.user_id);
          // Gonna pass back a generic check again soon
          return null;
      }
  
      const docs = snapshot.docs;
      // Empty array of post prms to return
      console.log("The snapshot returned: " + docs);
      var all_prms = [];
      // Create each doc as a post
      docs.forEach(doc =&gt; {
          var post = new Post(doc.data());
          console.info("Post data: " + doc.data());
          all_prms.push(post);
      });
      return Promise.all(all_prms);
   })
   .catch(err =&gt; {
      console.log("Error getting posts: " + err);
      return;
   });
  };
  </code></pre>
  
  <h2>Results</h2>
  
  <p>Every attempt to query data from App B's database returns no documents. I can verify documents exist and meet the criteria for the query. </p>
  
  <p>Any advise on things that I may be doing wrong would be really appreciated. I should conclude by stating that I am not a web developer and have little experience. </p>