How to save MongoDB files to a local machine using Python

Source: Internet
Author: User
This article mainly introduces how to save MongoDB files to a local place using Python, and describes how to use Python to call the gridfs method of the pymongo module to operate MongoDB files, for more information about how to save MongoDB files to a local machine, see the example in this article. We will share this with you for your reference. The details are as follows:

The documents on MongoDB are operated through GridFS. Python can also connect to the MongoDB database through pymongo and use the gridfs method of the pymongo module to operate the documents. The following example saves the excel file stored in GridFS on MongoDB to a local device.

From pymongo import export clientimport gridfsclient = MongoClient ('mongodb: // username: pwd@192.168.1.22: 27017/send_excel ') db = client. js_send_excelfs = gridfs. gridFS (db) files = fs. find () print ('total: ', files. count () for ffle in files: if ffle.filename.find('.xls ')> 0: with open (ffle. filename, 'WB ') as f1: f1.write (ffle. read ())

For more information about how to save MongoDB files to a local machine in Python, refer to PHP!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.