问题描述
C:\Programs\MongoDB\bin>mongofiles.exe list
connected to: 127.0.0.1
test123.txt 6
test123.txt 22
test123.txt 44
test456.txt 53
test456.txt 53
test456.txt 53
test456.txt 53
test456.txt 53
test456.txt 15
C:\Programs\MongoDB\bin>
当我做mongofiles get test456.txt
时,我总是得到最后一个
我把那个名字放在GridFS中的文件.我如何获得
其他/以前的,只要它们都有重复的名称?
When I do mongofiles get test456.txt
I always get the last
file which I put with that name in GridFS. How do I get the
other/previous ones provided they all have duplicate names?
根据我需要指定的文档:
According to the documentation I need to specify:
文件名,该文件名可以是:
上的文件名您本地文件系统或GridFS对象."
"A filename which is either: the name of a file on
your local's file system, or a GridFS object."
http://docs.mongodb.org/manual/reference/program/mongofiles /
但是在我看来,"GridFS对象"到底是什么意思.
But it's not really clear to me what "a GridFS object" means in this context.
推荐答案
在此上下文中,"GridFS对象"表示存储在GridFS集合中的对象的名称. --local
可能最好地解释了这种区别. mongofiles手册页上的选项.
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.
您在这里需要考虑的是,已经完成的工作是使用mongofiles实用工具提交文件名相同"的项目.如该实用程序的手册页所述,put
的默认行为(请参见命令)选项是在商店中创建新条目.可以使用 --replace
选项覆盖可以找到任何现有内容,并用您创建的新内容覆盖.
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.
简而言之,无论文件是否包含不同的内容,您都使用相同的对象名称"创建了几项内容.就mongofiles实用程序而言,它只知道如何通过对象名称"进行获取,因此它将按照规则检索它找到的第一个对象.
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.
现在,在大多数GridFS的API实现中,实际的get
操作通常由_id
完成.通过这种方式创建的每个对象"仍然具有其自己唯一的_id
值,因此,在应用该值后,便可以获取所需的对象".
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.
某些API实现添加了其他查询类型方法,以便通过文件名"或其他元数据信息进行查找.但是大多数情况下它们不会打扰,因为它们实际上只是标准的 .find()
或对任何集合进行的 .findOne()
操作内容元数据和引用(默认为fs.files).这提供了超过合理数量的方法,可以查找"特定对象并通过该API的get
接口发出该_id
值.
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.
因此,尽管mongofiles
是用于从命令行执行基本CRUD类型操作的好工具,但它只是一个工具,而不是如何做"的主要实现.因此,作为实用程序,它使用对象标识符的文件名"部分提供了一种设置和获取对象的便捷"形式.
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.
还值得注意的是,您应该确实像对待文件系统一样对待GridFS存储,并像文件系统中要求的那样保持文件名"的唯一性.
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.
但是对于mongofiles
实用程序,名称"是您检索信息所要做的全部工作.尝试不要这样做,或者实际上使用您选择的语言API来完成工作.
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.
这篇关于MongoDB-mongofiles的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!