【问题标题】:How to associate a text file in a collection with an image in a fs collection?如何将集合中的文本文件与 fs 集合中的图像相关联?
【发布时间】:2014-12-20 16:06:12
【问题描述】:

我正在开发流星的后端,现在我正试图以某种方式将文本文件与图像相关联。有没有办法将文本文件存储在fscollection 中?如何将它们关联到两个不同的集合中?

这是我的两个收藏:

Images = new FS.Collection("Images", {
  stores: [new FS.Store.FileSystem("Images", {path: "~/padonde/uploads"})]
});

Reynosa = new Mongo.Collection("Reynosa");

在 FsCollection 中,我存储图像,而在另一个集合中存储数据,但它们都是同一记录的一部分。

【问题讨论】:

  • 为什么不在集合中添加对图像 ID 的引用?

标签: node.js mongodb collections meteor


【解决方案1】:

您可以像这样在 FSCOllection 中使用元数据

在同一个 FSCollection 中你应该使用这个插入函数:

Template.templateName.events({
'click #clickEvent' : function(){

var file = $('#addImagenPromocion').get(0).files[0]; // Stores temporaly the FSFile
var fsFile = new FS.File(file); // take the FS.File object
fsFile.metadata = {nameValueMetadata:"Cool Stuff"};
Images.insert(fsFile);
}

});

因此,在此之后,如果您运行 Images.find().fetch();,则在 FSCollection 上插入一些元数据

您将在文档中看到 nameValueMetada:"cool stuff"

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-05-17
    • 1970-01-01
    相关资源
    最近更新 更多