occam98
occam98

Reputation: 321

Displaying elements from two different collections in meteor

I have two different meteor collections, one a file collection to store images:

 Images = new FS.Collection("images", {
  stores: [new FS.Store.FileSystem("images", {path: "~/uploads"})]
});

and the other a collection to store information about these images:

Photos = new Mongo.Collection("photos");
Photos.attachSchema(new SimpleSchema({
  userId:{
    type: String,
    autoValue:function(){return this.userId},

  },
  userName:{
      type: String,
      autoValue:function(){return Meteor.users.findOne({_id: this.userId}).username},
  },

  groupMembers: {
    type: String
  },
  comments: {
    type: String,  
    autoform:{
        rows: 5
    }
  },
  fileId: {
    type: String
  }
}));

I built this helper function to help display the data on a template:

Template.imagesSubmitted.helpers({
       photos: Photos.find(), 
       image: function(){Images.findOne({_id: Template.instance().data.image}).url();
        }
    });

Images.allow({
  download: function () {
    return true;
  },
  fetch: null
});

And here is the HTML code to display the images and information about the photos:

</template> 

<template name = "imagesSubmitted">
    List of photos
    {{#each photos}}
    <div class = "uploadedImage">  
      This is an image
      {{> photo}}
      <img src="{{this.image}}" class = "tableImage" alt="thumbnail">

    </div>    
    {{/each}}

</template>

Unfortunately, the page doesn't display anything from either database. The images only display as the alternate "thumbnail" and {{>photo}} doesn't seem to display any information from the Photos collection.

Is there a way to fix this? Also is there a way to streamline this so that I'm only using one collection and still able to use cfs:autoform to create and publish the form that collects images?

Upvotes: 1

Views: 231

Answers (2)

durrrr
durrrr

Reputation: 352

Be sure to allow download function.
From the docs:

Images.allow({
    download: function(userId, fileObj) {
        return true
    }
})

Upvotes: 1

peter pawar
peter pawar

Reputation: 106

Did you tried by using that query in your browser console? Like Photos.find().fetch(); And are you defining photo template?

Upvotes: 1

Related Questions