Skip to content

Instantly share code, notes, and snippets.

@kamiljozwik
Created October 3, 2017 14:13
Show Gist options
  • Save kamiljozwik/977036aa5a173d1ed9785ee96c7a9f9f to your computer and use it in GitHub Desktop.
Save kamiljozwik/977036aa5a173d1ed9785ee96c7a9f9f to your computer and use it in GitHub Desktop.
main.js file for Meteor server
import { Meteor } from 'meteor/meteor';
import { collectionName } from '../../imports/collections/collectionName';
Meteor.startup(() => {
// Place to generate data
// or Check to see if data exists in the collection
// or See if the collection has any records
// or ny other logic...
Meteor.publish('publicationName', function([arg]) { // arguments 'arg' is optional
return collectionName.find({}, { limit: arg }); // find everything, but limit to whatever passed to arg - optional
});
});
@kamiljozwik
Copy link
Author

kamiljozwik commented Oct 5, 2017

Bardziej skomplikowany publish:

Meteor.publish('publicationName', function() {
    const user = Meteor.users.findOne(this.userId);
    if (!user) { return; }                                                // jeżeli ktoś wchodzi na stronę i jest niezalogowany, nic mu nie pokazuj
    const email = user.emails[0].address;                  // pobierz adres email zalogowanego użytkownika

    return collectionName.find({
      sharedWith: { $elemMatch: { $eq: email }}
    });
  });

Look at the sharedWith property, inside this property this should be an array and inside of this array do an $elemMatch operation, where we want to find an element equal to email.

Możemy mieć zdefiniowanych kilka publications w jednym pliku.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment