GridFS:清除所有未引用的文件 [英] GridFS: Clean out all unreferenced files
问题描述
我刚开始将内容存储在MongoDB的GridFS中.在测试过程中,我注意到正在创建许多文件,但没有正确删除它们.我有一个集合users
,其中有一个字段avatar
.它包含文件的ObjectId
.
I have just moved towards storing things in my GridFS in MongoDB. During testing, I noticed many files are being created but not deleted properly. I have a collection users
, which has a field avatar
. It contains the ObjectId
of the file.
现在,我想使用一些命令来删除所有未在其中引用的files
和chunks
.是否可以通过一个查询做到这一点?也许是减少地图"?
Now I'd like to have some command I could use to remove all the files
and chunks
that are not referenced there. Is it possible to do that with one query? Maybe 'map-reduce'?
我也不知道如何正确地删除node-mongodb-native
中的GridFS文件.
Also I am not sure how to properly delete GridFS-Files in node-mongodb-native
properly.
推荐答案
?现在,我想使用一些命令来删除所有未在其中引用的文件和块.
? Now I'd like to have some command I could use to remove all the files and chunks that are not referenced there.
此处的关键术语已被引用". MongoDB没有任何联接,因此,它没有引用"的概念.
Key terms here is "referenced". MongoDB does not have any joins and therefore, it does not have concept of "references".
也许是'map-reduce'吗?
Maybe 'map-reduce'?
Map/Reduce是一种查询工具,而不是数据修改工具.较新的聚集框架"也是如此.
Map / Reduce is a query tool, not a data modification tool. The same is true of the newer "Aggregration Framework".
您需要做的是循环浏览文件,并分别检查每个文件的引用.然后,您将能够删除这些文件.
What you will have to do is loop through your files and check the references for each one individually. You will then be able to delete those files.
看看一些已记录的示例如何发布这些删除内容.
Take a look at some documented examples on how to issue those deletions.
这篇关于GridFS:清除所有未引用的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!