title: I am trying to get the _id from the bucket Grid FS to another mongo document
body: <p>I am trying to get the _id from the bucket Grid FS to another mongo document. </p>
  
  <p>These are the constructor object:</p>
  
  <pre><code>let Upload = function(data, file, userid) {
    this.data = data
    this.errors = []
    this.userid = userid
    this.file=file  
  }
  </code></pre>
  
  <p>here is the function I am having trouble with and the problem is that the this.data is undefined even though I am using a => function which shouldn't change the this keyword source:</p>
  
  <pre><code>Upload.prototype.create = async function() {
    return new Promise((resolve, reject) =&gt; {
      this.cleanUp()
      this.data.file.forEach((element,index)=&gt; {
  
  
        fs.createReadStream('./uploads/'+element.filename).
          pipe(uploadStream= bucket.openUploadStream(element._id,'./uploads/'+element.filename)).
          on('error', function(error) {
            assert.ifError(error);
            console.log(error)
          }).
          on('finish', function() {
            console.log('Done');                          
            console.log('fs.files._id:'+uploadStream.id)
            try{
            this.data.file[index]._id=uploadStream.id //this is line 62
            }catch(e)
            {console.log('error on line 62',e)}
  
          })
      })
      this.validate()
      console.log('data file filename:'+this.data.file[0].filename)//why is this defined and working...
      console.log('data file id:'+this.data.file[0]._id)//but this one is not
  
      if (!this.errors.length) {
        // save upload into database
  
  
          uploadsCollection.insertOne(this.data).then(() =&gt; {
            resolve()
  
        }).catch(() =&gt; {
          this.errors.push("Please try again later.")
          reject(this.errors)
        })
      } else {
        reject(this.errors)
      }
    })
  }
  </code></pre>
  
  <p>this is in the cleanup() function:</p>
  
  <pre><code>this.data = {
      title: this.data.title.trim(),
      comment: this.data.comments.trim(),
      file: this.file,
      createdDate: new Date(),
      author: ObjectID(this.userid)
    }
  </code></pre>
  
  <p>Here is the console:</p>
  
  <pre><code>[nodemon] restarting due to changes...
  [nodemon] starting `node db.js`
  { fieldname: 'myFiles',
    originalname: 'party.xlsx',
    encoding: '7bit',
    mimetype: 'application/octet-stream' }
  size of file: 8375 
  ok size
  data file filename:party.xlsx
  data file id:undefined
  Done
  fs.files._id:5df327ebc7686e05e82851fa
  error on line 62 TypeError: Cannot read property 'file' of undefined
      at GridFSBucketWriteStream.&lt;anonymous&gt; (C:\Users\colin\Documents\gelc-upload\models\Upload.js:95:21)
      at GridFSBucketWriteStream.emit (events.js:203:15)
      at C:\Users\colin\Documents\gelc-upload\node_modules\mongodb\lib\gridfs-stream\upload.js:284:13
      at result (C:\Users\colin\Documents\gelc-upload\node_modules\mongodb\lib\operations\execute_operation.js:75:17)
      at session.endSession (C:\Users\colin\Documents\gelc-upload\node_modules\mongodb\lib\operations\execute_operation.js:64:11)
      at ClientSession.endSession (C:\Users\colin\Documents\gelc-upload\node_modules\mongodb\lib\core\sessions.js:135:41)
      at executeCallback (C:\Users\colin\Documents\gelc-upload\node_modules\mongodb\lib\operations\execute_operation.js:59:17)
      at insertDocuments (C:\Users\colin\Documents\gelc-upload\node_modules\mongodb\lib\operations\insert_one.js:34:21)
      at handleCallback (C:\Users\colin\Documents\gelc-upload\node_modules\mongodb\lib\utils.js:129:55)
      at coll.s.topology.insert (C:\Users\colin\Documents\gelc-upload\node_modules\mongodb\lib\operations\common_functions.js:270:5)
  </code></pre>