Meteor publish filter fields if other field exist (solved)

#1

I have a collection that two fields dependent on each other, and one of them can return to the client; something like this,

    Books.find({},{
    fields:{
        user : function(){
            if(this.private == true){
                return 0
            }else{
                return 1
            }
        },
        private:1
    }
})

how can do that?

#2
Books
  .find({})
  .map(({user, ...rest}) => 
    rest.private ? {...rest} : {...rest, user}
  )
#3

Thank you @mrzafod,
but this code gives me ERR :
Publish function returned an array of non-Cursors
and nothing published in the client.
I found something that works ,this is it :

let self = this;

let handle = Stories.find({},{
          fields: {
              '_id':1,
              'title':1,
              'pictures':1,
              'createdBy':1,
              'unknown':1
          }
      }).observeChanges({
  added: function(id, fields) {
    self.added("stories", id, filterField(fields));
  },
  changed: function(id, fields) {
    self.changed("stories", id, filterField(fields));
  },
  removed: function(id) {
    self.removed("stories", id);
  }
});

self.ready();

self.onStop(function() {
  handle.stop();
});
let filterField = function(fields) {
    fields.unknown ? delete fields.createdBy : delete fields.unknown
     return fields;
   }