问题
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