Meteor Publish Problem


#1

@robfallows I need help. I’m not sure what I missing on my code… I’ve been a Meteor programmer but can’t seems find why this is not working.

Publish Code

Meteor.publish("LabRecordsByDone", function(depId) {
  const data = LabRecords.find(
    { status: "LAB_REC_DONE" },
    { sort: { createdAt: -1 } }
  );

  if (data) return data;
  return this.ready();
});

Client Code

class ResultsListQue extends Component {
  _handleClick = (recId, serId, customer_id, createdAt) => event => {

  };

  render() {
    const { recordsDONE, isDoneRecordsLoading } = this.props;

    if (isDoneRecordsLoading || recordsDONE.length === 0) {
      return <LocalLoader message={"Waiting for Queue..."} />;
    }

    return (
      <ListGroup>
        {recordsDONE.map((record, index) => (
          <ListGroupItem
            key={index}
            onClick={this._handleClick(
              record._id,
              record.service_id,
              record.customer_id,
              record.createdAt
            )}
          >
            <Row className="no-gutters">
              <div className="col-md-2">
                <div className="profile__avatar_services">
                  <img
                    src="/images/temp-profile.png"
                    // src={
                    //   this._renderPhoto(record.customer_id)
                    //     ? this._renderPhoto(record.customer_id)
                    //     : "/images/temp-profile.png"
                    // }
                    alt="avatar"
                  />
                </div>
              </div>
              <div className="col-md-7 _queinfodetails">
                {/* {this._renderName(record.customer_id)} */}
                {record.customer_id}
                <h5 className="subhead">{record.name}</h5>
              </div>
            </Row>
          </ListGroupItem>
        ))}
      </ListGroup>
    );
  }
}

export default withTracker(props => {
  const handler = Meteor.subscribe("LabRecordsByDone", "xawixN7QbnMz235ib");
  const isDoneRecordsLoading = !handler.ready();
  const recordsDONE = LabRecords.find({ status: "LAB_REC_DONE" }).fetch();
  return {
    recordsDONE,
    isDoneRecordsLoading
  };
})(ResultsListQue);

As you can see on the video below, when I changed the status directly in the mongodb, it doesn’t reactively remove the data. It needs to be refreshed to vanish
however when I edited that data back to os its original the data reactively appears


#2

Publications are not reactive - they are only executed once for each client’s subscribe(). As soon as you perform an evaluation in the code, that defines the publication. A hard refresh will re-subscribe and re-run the publication.

Try changing your publication:

Meteor.publish("LabRecordsByDone", function(depId) {
  const data = LabRecords.find(
    { status: "LAB_REC_DONE" },
    { sort: { createdAt: -1 } }
  );
  return data;
});

#3

Still the same… Isn’t that publish will automatically push to the client if the document inside my collection changes( added,remove, changed)?