【问题标题】:Drop all files in Gridfs with pymongo使用 pymongo 删除 Gridfs 中的所有文件
【发布时间】:2016-06-20 19:58:34
【问题描述】:

我想删除 GridFS 中的所有文件,但没有成功:

from pymongo import MongoClient
from bson.objectid import ObjectId


#add the file to GridFS, per the pymongo documentation: http://api.mongodb.org/python/current/examples/gridfs.html
db_file = MongoClient('192.168.0.16', 27017).db_file
fs = gridfs.GridFS( db_file )

db_file.drop_collection('files')
db_file.drop_collection('chunks')
db_file.drop_collection('test')
out = fs.get(ObjectId('57683734f525bc3d7420c262'))
print(out)
fp = open("test.mp3", 'wb')
fp.write(out.read())
fp.close()

在代码的最后,我仍然创建了一个文件,我仍然可以播放它。

【问题讨论】:

    标签: python mongodb pymongo gridfs


    【解决方案1】:

    试试这个:

    my_collection = db['collection_name']
    my_collection.drop()

    或删除数据库:

    client = MongoClient('192.168.0.16', 27017)
    client.drop_database("database_name")

    【讨论】:

      猜你喜欢
      • 2011-04-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-11-30
      • 1970-01-01
      • 2014-05-19
      相关资源
      最近更新 更多