【问题标题】:Storing a reference in another collection creates object but not string Meteor将引用存储在另一个集合中会创建对象而不是字符串 Meteor
【发布时间】:2015-09-29 02:59:41
【问题描述】:

我正在使用 collectionFS 为我的用户上传个人资料图片。我有两个集合,一个用于 userData,另一个用于图像。我正在尝试将图像参考附加到其他集合中。但我得到的是对象而不是 _id 字符串。有什么指点吗?

Biye = new Meteor.Collection ('biye');

Images = new FS.Collection("images", {
  stores: [new FS.Store.GridFS("images")]
});
// .....................upload.............

Template.upload.events({
  'change #exampleInput':function(event, template){  
    var file = $('#exampleInput').get(0).files[0]; 
    newFile = new FS.File(file);
    newFile.metadata = {'ownerId':Biye.findOne({ObjectID:this._id})};
    Images.insert(newFile,function(err,result){
      if(!err){
        console.log(result._id);
       }
     });
   }
})
newFile.metadata = {'ownerId':Biye.findOne({ObjectID:this._id})};

这一行返回一个完整的对象。我想要一个字符串。

【问题讨论】:

    标签: javascript mongodb meteor


    【解决方案1】:

    我能够使用

    存储字符串
    newFile.metadata = {'ownerId':Biye.findOne({ObjectID:this._id})._id};
    

    只是在末尾添加了._id

     newFile.metadata = {'ownerId':Biye.findOne({ObjectID:this._id})};
    

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-05-22
    • 1970-01-01
    • 2013-08-04
    相关资源
    最近更新 更多