[CSHARP-1935] How to delete chunk files Created: 08/Mar/17 Updated: 27/Oct/23 Resolved: 08/Mar/17 |
|
| Status: | Closed |
| Project: | C# Driver |
| Component/s: | API, Documentation |
| Affects Version/s: | 2.4.2 |
| Fix Version/s: | None |
| Type: | Task | Priority: | Blocker - P1 |
| Reporter: | Ummer Irshad | Assignee: | Robert Stam |
| Resolution: | Works as Designed | Votes: | 0 |
| Labels: | question | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Environment: |
OS : Windows 7 |
||
| Description |
|
In Mongocsharp driver, there was an option to delete documents in "fs.chunks" collection using gridfs object. Is it okay to delete documents in "fs.chunks" without using GridFS bucket object, ie, by using
Thanks in advance, |
| Comments |
| Comment by Ummer Irshad [ 10/Mar/17 ] | |||
|
Explanations are clear. | |||
| Comment by Robert Stam [ 09/Mar/17 ] | |||
|
The equivalent in 2.x to your 1.11 code is:
If you might be using non-default bucket names you could safely get the collection like this instead:
Note that if your upload failed part way whatever caused your upload to fail will almost certainly cause your attempts to clean up to fail in the same way. It is impossible to have chunk sizes greater than 16MB because each chunk is a document in MongoDB and MongoDB limits documents to 16MB (so the chunk actually must be slightly smaller than 16MB to allow room for a small amount of overhead for element names). You should always use GridFS methods to manipulate GridFS data when possible. It is possible to manipulate the GridFS collections directly if you wish because they are really just regular MongoDB collections, but if you do so you must exercise caution that you do not corrupt the data. | |||
| Comment by Ummer Irshad [ 09/Mar/17 ] | |||
|
I am trying to handle exception cases, where I would like to delete all the chunks based on Files_Id. In 1.11, using below code, we were able to do so.
My question is: if by chance some document got inserted partially to fs.chunks collection. In this case, we would like to retry insertion of same document once again after deleting the partially inserted fs.chunks. One more doubt: Can we delete a chunk having size more than 16 MB, using below code?
| |||
| Comment by Robert Stam [ 08/Mar/17 ] | |||
|
I'm not sure what 1.x method you are referring to. But the fs.files and fs.chunks collections are just regular collections in MongoDB and you can manipulate them directly like any other collection as long as you are careful about what you are doing and don't destroy the integrity of the GridFS data. If what you want to do is delete an entire GridFS files (both the fs.files directory entry and the chunks in fs.chunks) use:
If you manually delete a file's chunks in fs.chunks but don't delete the corresponding directory entry in fs.files you will have corrupted the GridFS bucket. |