Closed dpatte closed 7 years ago
GridFS, the MongoDB file storage spec that file-collection is built on, doesn't offer any block deduplication / reference counting functionality. Duplicate files require duplicate storage at the gridFS level. If you are fine with that, then the easiest way to copy a file is to use fc.findOneStream()
and fc.upsertStream()
and to pipe the readable stream into the writable one using the normal node.js mechanism.
If you do not wish to have physically duplicated gridFS files, then it gets more complicated. You would then need to create a new logical collection of some kind that is backed by the actual file collection, but implements file level deduplication (based on md5) and reference counting policies in the gridFS file metadata. It's doable, but you'd need to do the work, as gridFS and file-collection do not implement these features.
Hope that helps.
Thank you very much. Good advice.
Any hints on the easiest way of copying a file that exists in my meteor file collection? I want to make a copy, then modify an ownerId field that I have defined in the metadata, so that each user then has their own copy from that point on.