I've been struggling to extract data from a nested collection without success, as the dot notation in the HTML is not yielding any results.
Essentially, my goal is to only retrieve the necessary data from a nested collection. I am working on implementing a file upload feature for images and audio files, and then finding an efficient way to utilize these files. Currently, I am using the cfs:standard-packages and cfs:filesystem packages for this purpose.
The following code demonstrates a functional example of what I do not want – fetching the entire file object and accessing the data in the HTML. It would be ideal if I could somehow incorporate the dot notation into the mongo command. Alternatively, I could use _each, but I prefer fetching only the required data with each database call. In the provided example, I am passing an id for the complete file object like so:
Uploads.find({_id:Session.get('getpic')});
Additionally, please note that the actual file is stored in a directory on my local server.
The structure of the collection:
{
"_id" : "DXFkudDGCdvLpPALP",
"original" : {
"name" : "drink.png",
"updatedAt" : ISODate("2015-04-30T07:14:56.000Z"),
"size" : 127944,
"type" : "image/png"
},
"uploadedAt" : ISODate("2015-07-11T21:53:32.526Z"),
"copies" : {
"uploads" : {
"name" : "drink.png",
"type" : "image/png",
"size" : 127944,
"key" : "uploads-DXFkudDGCdvLpPALP-drink.png",
"updatedAt" : ISODate("2015-07-11T21:53:32.000Z"),
"createdAt" : ISODate("2015-07-11T21:53:32.000Z")
}
}
}
HTML representation:
<template name="renderImages">
{{#each showpic}}
<img width="300" height="300" src="/projectuploads/{{copies.uploads.key}}"/>
{{/each}}
Javascript logic:
Template.renderImages.helpers({
showpic: function() {
return Uploads.find({_id:Session.get('getpic')});
}
});