Coding the Display Books Functionality

Learn and build the display books functionality in the bookshop application.

Getting data from a MeteorJS application, as we’ve seen throughout this series, involves three steps. The steps involved are:

  • Data publication from the server.
  • Subscription to the data from the client.
  • Pulling the data into the React component using the useTracker function that’s imported from the meteor/react-meteor-data package.

Publishing book data

This functionality involves displaying books stored in the database at the frontend. Open the file located at imports/api/books/server/publication.js. Remember that data publication in Meteor takes place on the server.

On line 2, the BookCollection is imported. This is the Meteor collection that handles the books domain of data. We return a cursor from the BookCollection with the criteria that the coverImage property and bookurl property of a book must exist and shouldn’t be null. The $exists operator checks for the existence of a property in a collection, while the $ne operator means that the value of a property shouldn’t equal a certain value.

Get hands-on with 1200+ tech skills courses.