司 司长.使用 find() 时返回未定义的集合实例

FS.Collection instance returning undefined when using find()

本文关键字:未定义 返回 集合 实例 司长 使用 find      更新时间:2023-09-26

我在Web开发方面有点新手,所以如果我错误地使用FSCollection,我深表歉意。

我有一个FS。接收音频文件的集合实例

LectureAudio = new FS.Collection("lectureAudio", {
    stores: [new FS.Store.FileSystem("lectureAudio", {
        path:"~/digicog/audioUpload",
        filter: {
            allow: {
                contentTypes: ['audio/*'],
                extensions: ['mp3', 'wav', 'MP3', 'WAV']
            }
        }
    })]
});

我正在使用输入文件元素将音频文件插入集合中。

Template.audioControl.events({
  'change #lecAudioPath': function (event) {
    var files = document.getElementById("lecAudioPath").files;
    if(files.length != 0){  
      var lecName = Router.current().params._id;
      var audioFile = new FS.File(files[0]);
      audioFile.metadata = {LectureId: lecName};
      LectureAudio.insert(audioFile);
    }
   }
});

但是,当我在控制台中输入LectureAudio.find().fetch()进行测试时,我得到空括号 [ ]。即使当我使用以下命令检查我的 mongo 数据库时:

>db.getCollection("cfs.lectureAudio.filerecord").find()

我看到我的收藏已填充。

{ "_id" : "wwyQtZZNwicbheCch", "copies" : { "lectureAudio" : { "name" : "fWnQyQpEWSXRDeuJq.mp3" } }, "original" : { "name" : "test1.mp3", "updatedAt" : ISODate("2013-08-16T16:07:40Z"), "size" : 8087475, "type" : "audio/mp3" }, "uploadedAt" : ISODate("2015-03-07T06:05:53.589Z") }
{ "_id" : "3rBbFfnGAT3Z8Bkti", "copies" : { "lectureAudio" : { "name" : "Efn235HcCyGrm5TPx.mp3" } }, "original" : { "name" : "test2.mp3", "updatedAt" : ISODate("2013-08-16T16:07:52Z"), "size" : 8806339, "type" : "audio/mp3" }, "uploadedAt" : ISODate("2015-03-07T06:17:06.234Z") }
{ "_id" : "RJ7LLH7XhgG2PnP9g", "copies" : { "lectureAudio" : { "name" : "fWnQyQpEWSXRDeuJq.mp3" } }, "original" : { "name" : "test3.mp3", "updatedAt" : ISODate("2013-08-16T16:07:52Z"), "size" : 8806339, "type" : "audio/mp3" }, "uploadedAt" : ISODate("2015-03-07T06:18:30.454Z") }
{ "_id" : "9YY33kFFbP7oBMjmr", "copies" : { "lectureAudio" : { "name" : "y7KQmq3ReqcP7Pzyw.mp3" } }, "original" : { "name" : "test4.mp3", "updatedAt" : ISODate("2013-08-16T16:07:40Z"), "size" : 8087475, "type" : "audio/mp3" }, "uploadedAt" : ISODate("2015-03-07T20:50:21.226Z") }

如何显示收藏集?

您可能忘记发布和订阅该集合。

在服务器上:

Meteor.publish('lecture_audio', function () {
  return LectureAudio.find();
}

在客户端上:

Meteor.subscribe('lecture_audio');

此处文档中的更多信息