Meteor Publication and Subscription

In 2011, when Meteor was not around, When u hit a site build on Rails, The client(i.e your browser) sends a request to your app, which lives on the server. The app finds out which data the client need, which could be of any size. Once the right data has been selected, the app then translates into human-readable HTML (or JSON in case of API).

Finally, the App takes the HTML code and sends it to the client’s browser. The app’s job is done here.

The Meteor Way

The feature that makes Meteor different from others is while Rails App only lives on Server, Meteor App lives both on Server and Client. Simply put, Meteor takes part of your database and copy it to client. This has two implications: Firstly, instead of sending HTML code to the client, a Meteor app will send raw data and let the client deal with it. Secondly, you’ll be able to access and even modify that data instataneously without having to wait for round-trip to the server(latency compensation).

Publishing

The App’s database can contain thousands of documents, some of which might contain sensitive and private data, So we cannot just mirror complete database to the client, for security and scalability reasons.

So we’ll need a way to tell the Meteor which subset of the data can be sent to the client which is accomplised through publications
[cc lang=”javascript”]
//on the server
Meteor.publish(‘posts’, function(author) {
return Posts.find({author: author});
});
[/cc]
The above method tells Meteor App to send Only those posts to the client which are written by author.

Subscribing

There can be thousands of authors who write posts on the site. We need a way for clients to specify which subset of that data is needed at any particular time, and that’s exactly where subscription comes in.

Any data you subscribe to will be mirrored on the client thanks to Minimongo, Meteor’s client-side implementation of MongoDB.

For example, let’s say we’re currently browsing Tom Cliff’s profile page, and only want to display his posts.

[cc lang=”javascript”]
// on the client
Meteor.subscribe(‘”posts’, ‘bob-smith’);
[/cc]

Posted

in

, ,

by

Recent Post

  • Achieve High ROI With Expert Enterprise Application Development

    Nowadays modern-day enterprises encounter no. of challenges such as communication breakdown, inefficient business processes, data fragmentation, data security risks, legacy system integration with modern applications, supply chain management issues, lack of data analytics and business intelligence, inefficient customer relationship management, and many more. Ignoring such problems within an organization can adversely impact various aspects of […]

  • State Management with Currying in React.js

    Dive into React.js state management made easy with currying. Say goodbye to repetitive code and hello to streamlined development. Explore the simplicity and efficiency of currying for your React components today!

  • How Much Does It Cost to Develop an App in 2024?

    The price of bringing your app to life typically ranges from $20,000 to $200,000. This cost varies based on factors like which platform you choose, the complexity of features you want, and the size of your intended audience. However, costs can climb even higher for more complex projects, reaching up to $350,000.

  • Mastering Software Testing Strategies: Your Guide

    Implementing best software testing strategies is a crucial part of software development, ensuring that digital products meet industry standards. Defined by the International Software Testing Qualification Board, it encompasses a range of activities, both static and dynamic, throughout the software’s lifecycle. As an essential component of the Software Development Life Cycle (SDLC), the Software Testing […]

  • Your Complete Guide to Securing Your Kubernetes Cluster: Essential Tips for Beginners

    In today’s digital landscape, Kubernetes has emerged as the go-to solution for managing applications at scale. However, amidst its power lies a crucial concern: security. Ensuring the safety of your Kubernetes cluster is paramount to protecting your applications, data, and infrastructure. This comprehensive guide will walk you through essential practices and tips to help you […]

  • How to use Cloudinary in Node.js to upload images?

    It’s simple to use Cloudinary to upload images in a Nodе.js application, which can improve your app’s imagе management capabilities. Wе’ll go over how to sеt up and incorporate Cloudinary in your Nodе.js application for imagе uploads and how to use Cloudinary nodejs in this blog article. What is Cloudinary? Cloudinary is a cloud-based media […]