title: How can i store firebase data to json in local
body: <p>In my case I got the data from firestore now how can I save it to
  <code>serversettings.json</code>: </p>
  
  <pre><code>var temp = {}
  let query = db.collection('guilds')
  let data = query.get().then(snapshot =&gt; {
      snapshot.forEach(doc =&gt; {
          console.log(doc.id, '=&gt;',doc.data());          
      })
  </code></pre>
  
  <p>so I get the output as:</p>
  
  <pre><code>637301291068030997 =&gt; { welcomeChannelID: '&lt;#648968505160630285&gt;',
  guildMemberCount: 4,
  guildOwnerID: '348832732647784460',
  guildOwner: 'Ethical Hacker',
  prefix: '.',
  guildID: '637301291068030997',
  guildName: 'test server 3' }
  </code></pre>
  
  <p>and this:</p>
  
  <pre><code>GUqGqFanJuN7cRJx4S2w =&gt; {}
  </code></pre>
  
  <p>I need to save that data to <code>serversettings.json</code> </p>
  
  <pre><code>await fs.writeFile ("../serversettings.json", JSON.stringify(temp), function(err) {
      if (err) throw err;
      console.log('done');
      })
  </code></pre>
  
  <p>here temp is variable where multiple data is stored like a:{},b:{}....</p>
  
  <p>i tried <code>var temp = {} temp.table = []</code> and then <code>temp.table.push(doc.id, ':',doc.data())</code>
  but i get empty output so what can i do to get that expected output ?</p>
  
  <p>also, adding to that how can I update the values if that object is already present in <code>JSON</code> will the above function work the same will it override the same value or delete all other values example update prefix from. to, then <code>await fs.writeFile ("../serversettings.json", JSON.stringify(temp),.....</code> so the temp field has a value of only guild id and that field prefix will it update the only prefix and not delete anything else in that array?</p>
  
  <p>HERE is the code that added stuff to temp variable</p>
  
  <pre><code>    var temp = {}
      temp.guilds = []                                 // after some lines 
      snapshot.forEach(doc =&gt; {
              console.log(doc.id, '=&gt;',doc.data());    // output is above this code
              temp.guilds.push(doc.id = doc.data())    // output is below this code
          })
  </code></pre>
  
  <p>Above codes output </p>
  
  <pre><code>{ guilds:
     [ { guildID: '637301291068030997', // here missing doc.id field 
         guildName: 'test server 3',
         welcomeChannelID: '-',
         guildMemberCount: 4,
         guildOwnerID: '348832732647784460',
         guildOwner: 'Ethical Hacker',
         prefix: '.' },
       {}   // this missing thing before {} is (some number) also bracket is empty by the way so no worries 
    ] 
  }
  </code></pre>