title: Retrieve file from mongoDB using python
body: <p>I have doc file stored in mongodb. I want to retrieve stored doc file on mongoDB using python. Any suggestion will really be helpful. I'm unable to find article to move forward. All I could find is uploading file through python and retrieving through python. But I want to retrieve file stored on mongoDB which is not created on python but retrieving through python. P.S.: I stored file on mongodb gridfs using express js.</p>
  
  <p><strong>Upload.JS</strong>:: JS used to upload file on mongodb gridfs .</p>
  
  <pre><code>const util = require("util");
  const multer = require("multer");
  const GridFsStorage = require("multer-gridfs-storage");
  const mongoose = require('mongoose');
  const Grid = require('gridfs-stream');
  const mongoURI ='mongodb://localhost:27017/file_uploaded_new';
  const promise = mongoose.connect(mongoURI, { useNewUrlParser: true });
  const conn = mongoose.connection;
  let gfs;
  conn.once('open',() =&gt; {
    gfs = Grid(conn, mongoose.mongo);
    gfs.collection('uploads');
  });
  var storage = new GridFsStorage({
      db: promise,
      options: {useNewUrlParser: true, useUnifiedTopology: true },
      file: (req, file) =&gt; {
          return new Promise((resolve, reject) =&gt; {
              if (file.mimetype === 'application/vnd.openxmlformats- 
  officedocument.wordprocessingml.document') {
                  resolve({
                      bucketName: 'words',
                      filename: `${file.originalname}`
                  })
              } else {
                  reject(Error("File type has been rejected"));
              }
          });    
      }
  });
  var uploadFile = multer({storage: storage}).single("file");
  var uploadFilesMiddleware = util.promisify(uploadFile);
  module.exports = uploadFilesMiddleware;
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/8gPXc.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/8gPXc.png" alt="words.chunk file in MongoDB "></a></p>
  
  <p><a href="https://i.stack.imgur.com/4E0aK.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/4E0aK.png" alt="Words.file in MongoDB"></a></p>
  
  <p>I have successfully uploaded docx file in MongoDB. How can I retrieve the uploaded word file using python script?</p>