订阅收集文档的子数组

时间:2016-06-14 12:10:28

标签: javascript node.js mongodb meteor

我有一个集合,代表用户的上传文件,其结构如下:

{
  _id : SKHdspjhs92346
   files : [ { file_name : "1.txt" , file_path : "/home/test1"/} , { file_name : "2.txt" , file_path : "/home/test2"/}  ]
}

我想订阅此集合数组变换。

所以当客户端上传文件时我会做推送:

 AttachmentsList.update({_id : id},
                           { $push: { files :  {file_name : fileName, file_path: filePath}}});

删除后拉动:

AttachmentsList.update( {"_id": id }, {"$pull": { "files" : {file_name : fileName,file_path: filePath} } } );

我希望元素在模板中改变。有可能这样做吗?目前我有这个出版商

  Meteor.publish("attachments_list_limited", function (count,id) {


        var test =  AttachmentsList.find({_id : id}, { "files.$": 1 },{limit: count}, {sort: {"files.file_name": -1}});

        console.log("changed, gout elements: " + test.count());
        return test;

    });

但它没有像那样反应性地工作。

1 个答案:

答案 0 :(得分:0)

您可以查看https://github.com/peerlibrary/meteor-reactive-publish,尝试通过#autorun让您的发布对用户结构的更新做出反应。