Closed teu closed 6 years ago
This is an unfortunate side effect of how GridFS files are implemented in ODM. When you have a document with a file-mapped field, that field becomes a reference to the MongoGridFSFile object (through the doctrine/mongodb wrapper class). Technically, that's the data stored in fs.chunks
(assuming the default fs
prefix). The remaining fields in the document are stored in the single document you'd find in the fs.files
collection. If you would delete the file, ODM cleans up both the fs.files
document and the related chunks.
If you have a document that should exist irrespective of an attached file, I would suggest revising your schema so that your main document has a ReferenceOne or ReferenceMany relationship to a file-mapped document.
Hi, looks like a bug, as it does not remove the file completely and leaves the _id. If there is nothing you can do, think this one is ready to close, maybe a note in the docs though.
@teu: That does sound like a bug. I'd like to leave this open as a reminder to come up with a test case and investigate. If you're willing to create one yourself and attach it to this issue, which would be a huge help. There are examples of GH issue functional tests in the repository.
Closing this issue, as it's just a documentation problem. The implementation of GridFS in ODM didn't make it clear, but the file was actually the main content, with other fields mapped in the document being metadata belonging to the file. This is one of the reasons GridFS support is being rewritten for 2.0, to make this more clear.
There is a problem with the gridfs files deletion. going by description in https://doctrine-mongodb-odm.readthedocs.org/en/latest/reference/storing-files-with-mongogridfs.html?highlight=file
I created a document, the problem is, most of the times, the file is just temporary in mongodb (in my app anyway), and gets deleted after. The deletion (or $document->setFile(null) ) on the @MongoDB\File also removes all other fields in that document, besides the data itself. I have a bunch of statistical information in that document, and it all gets removed when I just remove the file. What's left is just the Id. This might be the way it was intended, however doesn't not really seam like the mapping is accurate here, as it obviously removes a lot more from the database, than I from the object.
The operation should just remove the data that has been removed from the object.
Crosspost from http://www.doctrine-project.org/jira/browse/MODM-175