title: How to write data to cloud Firestore using cloud Functions
body: <p>For a scheduling app I'm building in Flutter I'm trying to write data to my cloud Firestore database with cloud functions and cron jobs to make my app more self-sustaining. I'm stuck at the first step, which is trying to get my cloud function to write data to my cloud Firestore database. </p>
  
  <p>Below I've included links to pictures on github of how my current data is structured in Firestore. What I want is to add named documents to the collection 'days' with a subcollection of 'hours', in which there are more named documents with the fields 'hour' and 'reserved'.</p>
  
  <p>Picture 1: <a href="https://github.com/winckles/rooster/blob/master/Schermafbeelding%202019-11-07%20om%2014.27.55.png?raw=true" rel="nofollow noreferrer">https://github.com/winckles/rooster/blob/master/Schermafbeelding%202019-11-07%20om%2014.27.55.png?raw=true</a></p>
  
  <p>Picture 2: <a href="https://github.com/winckles/rooster/blob/master/Schermafbeelding%202019-11-07%20om%2014.28.26.png?raw=true" rel="nofollow noreferrer">https://github.com/winckles/rooster/blob/master/Schermafbeelding%202019-11-07%20om%2014.28.26.png?raw=true</a></p>
  
  <p>Below I have also included my try on getting data in Firestore. </p>
  
  <pre><code>const functions = require('firebase-functions');
  const admin = require('firebase-admin');
  admin.initializeApp(functions.config().firebase);
  
  // admin.firestore().collection('days').add({original: original}). then(writeResult =&gt; {
  //
  // });
  
  exports.updateData = functions.https.onCall((data, context) =&gt; {
      const days = admin.firestore().collection('days');
      return days.doc(data['2019-11-08/hours/001']).set({
          hour: '08:00-09:00',
          reserved: '',
      });
  });
  </code></pre>
  
  <p>Ideally I would want the cloud function to add 14 documents (eg. 2019-11-06 to 2019-11-19) to the collection 'days' at the same time. Those documents would then each have a subcollection 'hours' with the data from the second screenshot (so the documents 001, 002, 003 etc. with the fields hour and reserved).</p>
  
  <p>I read the documentation on cloud functions and mostly found triggers when data is written to Firestore, but this is not what I want. I also tried the quickstart function samples but with no success. It shouldn't be too hard but I can't seem to figure it out. I'm using Javascript to write the cloud function in. Any help/tips would be greatly appreciated!</p>