def __flush(self):
        """Flush the file to the database.
        """
        try:
            self.__flush_buffer()

            if "md5" in self._file:
                self._file["md5"] = self._file["md5"].hexdigest()
            # The GridFS spec says length SHOULD be an Int64.
            self._file["length"] = Int64(self._position)
            self._file["uploadDate"] = datetime.datetime.utcnow()

            return self._coll.files.insert_one(
                self._file, session=self._session)
        except DuplicateKeyError:
            self._raise_file_exists(self._id)
Flush the file to the database.
        
stackoverflow/venv/lib/python3.6/site-packages/gridfs/grid_file.py