[JAVA-1205] GridFs Created: 08/May/14 Updated: 08/May/14 Resolved: 08/May/14 |
|
| Status: | Closed |
| Project: | Java Driver |
| Component/s: | GridFS |
| Affects Version/s: | 2.4 |
| Fix Version/s: | None |
| Type: | Bug | Priority: | Minor - P4 |
| Reporter: | Ilario | Assignee: | Ross Lawley |
| Resolution: | Done | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Environment: |
OS X Maverick |
||
| Description |
|
I am using Gridfs for storing a big file in mongodb. This is my code to insert the file:
The file was successfully inserted intact, if I try to show it through the restful interface I had the follow response:
Now, I want to delete this bucket, this is my code:
Apparently the file has been deleted infact the response is:
but, if I show the collections in my console I have still my bucket (35.files,35.chunks). Why after the remove in the console I have still this bucket? is it a bug or I haven't understood some stuff? |
| Comments |
| Comment by Ross Lawley [ 08/May/14 ] |
|
That is to be expected, MongoDB aggressively preallocates data files to reserve space and avoid file system fragmentation. To free up that space you'd have to drop the database - that would also remove any other collections! The storage documentation explains in more detail about MongoDB's storage engine. Also the smallFiles configuration option may be of interest as well. Ross |
| Comment by Ilario [ 08/May/14 ] |
|
I mean, if I have only one database (test) with only one Gridfs file (35.files and 35.chunks) the dimension of the db (show dbs) is 0.20 Gb. |
| Comment by Ross Lawley [ 08/May/14 ] |
|
ilamaiolo If that answers your concerns, I'll close this ticket. |
| Comment by Ross Lawley [ 08/May/14 ] |
|
When you say dimension - what do you mean? If you mean the amount of space the database takes up on disk then that is as expected, but the space is on the free list and as the database grows will be used by other collections / documents. For more information about storage see the storage documentation For future, the best place for questions regarding MongoDB usage or the Java driver specifics is the mongodb-user mailinglist or stackoverflow as you will reach a boarder audience there. Ross |
| Comment by Ilario [ 08/May/14 ] |
|
Yes, you have been very clear. Thanks in advance for your help. |
| Comment by Ross Lawley [ 08/May/14 ] |
|
Hi, GridFs is a convention build upon MongoDB and exists solely in the driver code. It helps facilitate the storing and retrieving files that maybe bigger that the 16MB document limit. When calling gridFs.remove(ObjectId) in the background it simply removes all matching documents and as such doesn't drop any collections, which is why you are still seeing them in the console. You have to manually drop the collections if they are no longer required. I should also mention GridFS can also store multiple versions of a file. For example if you create a file with the name "35" and then later create a new file "35", it won't overwrite the original file but instead stores the new file as well. gridFs.remove(ObjectId) will only remove one version of that file (the one with the matching _id) but if you wanted to totally remove the file then calling: gridFs.remove(filename) is the way to do that. I hope that helps clear it up! Ross |