Load data from mongodb in meteor and accessing globally

I need to load a preconfigured data from mongodb to the app. I don’t want to display this data on the screen. I will be using for some business validations. I know i can use Meteor.call to achieve this, just checking any other options are there in meteor.

Ideally any options to load this data one time and globally accessed across the application will be good.


Meteor.call is probably the right ones to use.

You could also use Meteor.subscribe, but that will also watch for any updates to data.
Or you could even write it into the html delivered to the client straight away

Thanks, is that possible to call only once and used across multiple components. For example, can we able to load this data in lib folder location and access across it.

You can handle this with a module that stores the data and can be imported where the data is needed, or you can just stick it on the window so it’s available globally

// client/main.js
window.globalConfig = {};
Meteor.call('fetch-global-config', function (error, result) {
  if (error) throw error;
  window.globalConfig = result;

Which, despite the use of globals, is probably just fine

1 Like

If you publish data with null argument, that data will be automatically available to all connected clients.

very roughly:

Meteor.publish(null, function(){
    return UserPreference.find({userId: this.userId });

I have used this to get user preference globally for view layer (i.e. gird, list…), I’m not sure if it has any side-effects or disadvantages over Meteor.call.