0

I used GridFS Package to create a file upload system in meteorjs this is the Code

     var files = event.target.files;
     FS.Utility.eachFile(event, function(file) {
           Files.insert(file, function(err, fileObj) {
             // Inserted new doc with ID fileObj._id, and kicked off the data upload using HTTP
             fileObj.createdBy = Meteor.userId();
             console.log(currentProject);

             if (err) {

             } else {
               console.log(fileObj);
               console.log(Files);

             }
           });
           v
But i am facing a problem when i return the files. i am using the Find method
return Files.find({});

My problem is while uploading the file i added a property called createdBy that contain the current user id now i want to filter all files to get just the ones that are uploaded by the current user and i noticed that the Find method is in the FS.collection and not in the FS.file where all the properties are so i can not do something like

retuen Files.find({createdBy:Meteor.userId()});

so how to solve this is there anyway to get the properties files from a current file then filter them again? Thanks in advance

Fady Samir
  • 13
  • 4

1 Answers1

0

You are adding the property after it has been inserted. Do it beforehand, otherwise it doesn't get stored:

       file.createdBy = Meteor.userId();
       Files.insert(file, function(err, fileObj) {  ...

After that you can totally use Files.find.

Christian Fritz
  • 20,641
  • 3
  • 42
  • 71