Meteor Files findOne return undefined

空扰寡人 提交于 2020-01-06 08:03:18

问题


i use Meteor Files for uploading files. i managed to save it to database and filesystem but i failed to get those files from its findOne method. here is my product collection :

import { Mongo } from 'meteor/mongo';
import { Meteor } from 'meteor/meteor';
import Images from './imagesCollection';


const ProductCollection = new Mongo.Collection( 'products' );

ProductCollection.helpers({
   photos() {
      return Images.findOne({ meta: { productId: this._id } });
   }
});

and here is my image collection:

const Images = new FilesCollection({
collectionName: 'Images',
allowClientCode: false,
storagePath: () => {
    return `${process.env.PWD}/public/assets/products/`;
},
onBeforeUpload: function(file) {
    if (/png|jpe?g/i.test(file.extension)) {
        return true;
    }

  }

});


export default Images;

i used meteor-collection-helper to get image associated with the product.

class ProductBox extends Component {
constructor(props) {
    super(props);

    this.productRemove = this.productRemove.bind(this);
    this.selectUpdate = this.selectUpdate.bind(this);
}

render() {
    console.log(this.props.produk.photos())
    return (
    );
  }
}

export default ProductBox;

whenever i consol log out the image collection it returned undefined or the cursor failed to get the data. please point me out which part i'm doing it wrong? any help would be appreaciated!

来源:https://stackoverflow.com/questions/49627152/meteor-files-findone-return-undefined

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!