What is the best way to ensure that a collection is only released when necessary?

Within my application, I have a streamlined public profile that showcases only a portion of the fields stored in my Meteor.users collection. While I understand that I can selectively publish specific fields from the collection, I am concerned about unnecessary data being transmitted to users when they subscribe to it. As a solution, I aim to publish this data on demand, meaning it will only be accessible when requested by the user - for example, upon visiting

/public-profile/425f7834985r79na8syf
.

Answer №1

  1. Create a route that requires a parameter (for example, /profile/:_id)
  2. Ensure your route subscribes to a publication using the provided _id, like this:

    Meteor.subscribe('getProfile', id);
    
  3. Set up the publication as follows:

    Meteor.publish('getProfile', function(id){
      return Meteor.users.find({_id: id}, {fields: {importantField: 1, additionalField: 1}});
    });
    

Keep in mind that even though we anticipate only one document, the publish function returns a cursor and not a single document with findOne().

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Ensuring AngularJS ui-router/app waits for $http data to avoid Flash of Unstyled Content (FOUC)

My question or situation pertains to the states defined in my AngularJS application. Here is an example of how I have them structured: $stateProvider .state('myApp', { abstract: true, template: '& ...

The elements being parsed are appearing as undefined

Currently, I am attempting to analyze this JSON structure: { "customers": [ { "name":"joe" , "cars":[ {"name":"honda","visits":[ {"date":"01/30/14","Id":"201"}, {"date":"01/30/14","Id":"201"}, {"date":"02/12/14","Id":"109"} ...

JavaScript for Time-Sensitive Events

I created a cutting-edge live-tracking website for my school that features two stunning fullscreen graphs, G1 and G2. My goal is to showcase G1 for 10 minutes before switching to G2 for 2 minutes. I brainstormed a possible solution: (Not considering syntax ...

Consecutive POST requests in Angular 4

Can you assist me with making sequential (synchronous) http POST calls that wait for the response from each call? generateDoc(project, Item, language, isDOCXFormat) : Observable<any> { return this.http.post(this.sessionStorageService.retriev ...

Interacting with elements on top of a video is inhibited when using the YouTube player on an iPad through Safari

Whenever I try to create a youtube player in an iframe the usual way (like shown here), I encounter an issue where any touch on the video player is intercepted by the video controls, making it impossible for users to tap on a button placed above the iframe ...

Breaking a loop when data is found: Utilizing Node, MongoDB, and loop

Here is a snippet of my code: var mongo_client = require('mongodb').MongoClient, dataStorage; lib = { [...] find: function(res, param, callback) { var parentPath = param.path; while (parentPath !== '/') { ...

Personalize the behavior of input type=file

I currently have a file browser included on my webpage using the following code: <input type="file" /> My goal is to display a JavaScript "confirm" popup when the browse button is clicked. If the user clicks "OK" on the popup, then the file browser ...

The print preview displays a single div in an incorrect location

I have successfully created a javascript plot and wanted to incorporate a legend that overlaps the plot. Unfortunately, the function I used does not support directly overlapping legends, but it does allow for placing the legend in a separate div. To work a ...

Preventing Bull Queue from automatically re-starting jobs upon server restart

Currently, I am utilizing the bull queue system for processing jobs. Imagine a scenario where a job is in progress with an active status and I restart my development server. Upon restarting the worker script, the job remains in the active state within the ...

The Docker-compose encountered an error when it could not locate the react-scripts. This resulted in an npm error with the code EL

Encountered an error while running the docker-compose up command for my Node.js application with MongoDB. The objective is to containerize this application and deploy it on Docker Hub. 1. Creating mongo ... done 2. Creating app ... done 3. Attaching t ...

Having trouble utilizing Mongo show commands as I keep encountering errors that say 'show: command not found'

I have successfully set up MongoDB on my system, but I am encountering an issue with running mongo commands. Whenever I try to use the command show collections, I receive an error stating show: command not found. How can I resolve this issue? I installed ...

Access JSON value using jQuery by key

Creating a JSON structure that contains information about attendees: { "attendees": [ { "datum": "Tue, 11 Apr 2017 00:00:00 GMT", "name": " Muylaert-Geleir", "prename": "Alexander" }, { "datum": "Wed, 12 Apr 2017 ...

Optimizing MongoDB Performance with Array Queries and Indexing

In my collection of cats, each document contains information about the cat and its meals. The meals array can have up to 3 elements. { "catID": 10001, "catName": "muffler", "meals" : [ { "mealID" ...

Is it possible to manipulate videos embedded in an iframe using javascript?

It's common knowledge that JavaScript commands from Google can be used to control YouTube videos, while Vimeo provides its own JavaScript commands for their videos. Both videos are typically embedded within 'iframes' on websites. I'm ...

I am looking to create a PHP script that restricts access to individuals under the age of 18 based on the current

I'm looking for a way to use Php, javascript, or ajax to restrict access for individuals under 18 years old based on the current date. Any suggestions on how I can achieve this? Could someone please review my code for calculating age onblur or onSubm ...

An AngularJS project utilizing exclusively EJB

Can an AngularJS application be built directly with EJB without needing to expose them as REST services? Many examples on the internet show that eventually REST services are required to provide data to AngularJS. This means that EJB methods must be expos ...

Seeking specific parameter in a JSON array using JavaScript: A guide

Currently, I am working on a project that involves retrieving Facebook news feed data using the graph API. Upon receiving the JSON object, I display it on the page. The "Likes" section is presented as an array of JSON objects like this: data.likes: { ...

module-deps is unable to resolve relative require statements

Attempting to navigate the dependency graph of a Node.js file using module-deps has presented a challenge. Below is a mostly minimal testcase: var resolve = require('resolve'), mdeps = require('module-deps'), builtins = require ...

Prevent refreshing Google Maps when changing routes in AngularJS

Utilizing a Google map as the background for my website adds a unique visual element to the data displayed on different routes. However, I have encountered an issue where the map reloads with every route change, resulting in an unsightly flash of white tha ...

What is the mechanism behind AJAX functioning without the need to refresh the page?

I came across a code (not written by me) for a button that allows users to bookmark a person and add them to a shortlist. Here's how the code looks: Here is the JS & Ajax portion: self.isMarked = ko.observable(@(Model.Application.IsMarked ? "tru ...