Hide fields in method?

Hey,
is it possible to hide fields in a Meteor method (if I return an doc array). For example:

Meteor.methods({
 'videos.get': function() {
    return Videos.find({},{fields:{md5:0}}).fetch();
  }
});

This still shows the md5 fields on the client.

If you want to completely hide md5 clientside, you should use a filter on publication.

You cannot use a method to return a cursor.

You can return an array of docs:

Meteor.methods({
 'videos.get'() {
    return Videos.find({},{fields:{md5:0}}).fetch();
  }
});

which will honour your suppression of the md5 field.

Hey Rob,
sorry, my example code was wrong. I’m using .fetch() but still get the md5 field from the method. It only works if I add it to a publication. Currently I’m using this “ugly” solution:

Meteor.methods({
 'videos.get': function() {
    const videos = Videos.find({}).fetch();
    return videos.map((video) => new Video(_.omit(video,['md5'])));
  }
});

Video is an Astronomy model - omit removes the class and creates a new object which causes problems because I’m not able to call the helpers anymore. So it would be great if I could hide the fields straight in the mongo query.

Hmm. It’s working for me. Are you sure md5 is a top-level field?

1 Like