Well a "GridFS object" in this context means the name of the object stored in the GridFS collections. The distinction is possibly best explained by the --local
option on the mongofiles manual page.
What you need to consider here is that what you have done is submit items with the "same" filename using the mongofiles utility. As noted in the manual page for that utility, the default behavior for the put
(see commands) option is to create a new entry within the store. This can be overridden with the --replace
option so that any existing content is found and overwritten with the new content you have created.
In short, regardless of whether the files contain different content or not, you have created several things with the same "Object name". As far as the mongofiles utility is concerned, it only knows how to fetch by the "Object name" so it will just retrieve the first one it finds, by it's rules.
Now in most API implementations of GridFS, the actual get
operations are typically done by _id
. Every "Object" you created in this way does still have it's own unique _id
value, so when this is applied then you can get the "Object" that you want.
Some API implementations add additional query type methods in order to find by "filename" or other meta data information. But mostly they do not bother as these are really just standard .find()
or .findOne()
operations on whatever collection hold the content meta-data and references ( fs.files by default ). This provides a more than reasonable amount of ways to "find" a particular object and issue that _id
value through the get
interface of that API.
So while mongofiles
is a nice utility for doing basic CRUD type operations from the command line, it merely is a utility and not the main implementation of "how to do it". So as a utility it provides a "convenience" form of setting and getting objects, being using the "filename" part of the Object identifier.
Also worth noting is that you should really treat a GridFS store just like a filesystem, and keep your "filenames" unique just as would be required in a filesystem.
But as for the mongofiles
utility, the "name" is all you have to go on to retrieve information. Try not to do that, or really use your chosen language API to do the work instead.