Hi Guys,
Please i need your help. With this. Basically, i am trying to group all uploaded pictures with same student id as you can see in the metadata fields.
{ "_id" : "9RsXRp9oLks4SN6JN", "original" : { "name" : "67230241_616067498887445_6779395470583136256_n.jpg", "updatedAt" : ISODate("2019-08-02T12:39:51Z"), "size" : 53957, "type" : "image/jpeg" }, "metadata" : { "owner" : "quz9rYHscECfCvgcp", "student" : "vSC8voLrYXWktvTH6", "today_topic" : "Today Topic", "report_desc" : "Today has been focus on this and that.", "student_rate" : { "student_class" : "Mavi", "rating" : 4 } }, "instance_id" : "29053", "uploadedAt" : ISODate("2019-08-24T08:22:02.559Z"), "copies" : { "images" : { "name" : "67230241_616067498887445_6779395470583136256_n.jpg", "type" : "image/jpeg", "size" : 53957, "key" : "5d60f3abf1024075959b72c8", "updatedAt" : ISODate("2019-08-24T08:22:07.663Z"), "createdAt" : ISODate("2019-08-24T08:22:07.663Z") } } }
PLEASE GUYS! I REALLY DO NEED YOUR HELPS!
THANK YOU SO MUCH,
Hi @morningstardev13, could you explain a little more your problem? What are you looking for? what isnt working?
2 Likes
What I would do is the following, you first need to make a publication and subscribe to it from the client. This publication should be something like:
Meteor.publish('studentImages', function studentImages(studentId) {
return collectionName.find({ 'metadata.student': studentId }); //StudentId should be sent from the client.
});
In the client you would do a:
Meteor.subscribe('studentImages');
The subscribe will bring all the data and in order to get all the images of that user in the client (maybe as a array of strings where the strings are the urls), you should use the underscore package and use the _.pluck*() function:
const studentImages = collectionName.find({ 'metadata.student': studentId }).fetch();
const finalImages = _.pluck(studentImages, 'copies.images.name'); //Thinking that this is the field that has it
I hope I understood correctly.
2 Likes
Just a note on security: Don’t forget to check
your publication args to prevent injection attacks, and If you’re not intending anyone to be able to get a list of any users images, you’ll want to use this.userId
, or add other checks to makes sure only authorized users are able to subscribe to this publicaiton.
1 Like
Thank you so much guys @juanpmd you saved me some hours.
I followed your steps and got it worked.
Thank you to @copleykj for the security help. I appreciate it.
Love you,
2 Likes