peerlibrary/meteor-subscription-scope

Name: meteor-subscription-scope

Owner: PeerLibrary

Description: Scope queries on collections to subscriptions

Created: 2015-12-23 10:30:57.0

Updated: 2018-01-25 05:45:40.0

Pushed: 2018-01-16 18:35:56.0

Homepage: https://atmospherejs.com/peerlibrary/subscription-scope

Size: 10

Language: CoffeeScript

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

subscription scope

This Meteor smart package allows scoping of queries on collections only to documents published by a subscription.

Adding this package to your Meteor application extends subscription's handle with scopeQuery and publish endpoint function's this is extended with this.enableScope().

Both client and server side.

Installation
or add peerlibrary:subscription-scope
API

The subscription handle returned from Meteor.subscribe contain a new method:

Limiting is only done on documents, not on fields. If multiple publish endpoints publish different fields and you subscribe to them, all combined fields will still be available in all queries on the client side.

Inside the publish endpoint function this is extended with:

Examples

If on the server side you have such publish endpoint (using MongoDB full-text search):

or.publish('search-documents', function (search) {
is.enableScope();

r query = {$text: {$search: search}};
ery['score_' + this._subscriptionId] = {$meta: 'textScore'};

turn MyCollection.find(query);

Then you can on the client side subscribe to it and query only the documents returned from it:

subscription = Meteor.subscribe('search-documents', 'foobar');

sort = {}
['score_' + subscription.subscriptionId] = -1;

eturns documents found on the server, sorted by the full-text score.
llection.find(subscription.scopeQuery(), {sort: sort}).fetch();

eturns count of documents found on the server authored by the current user.
llection.find({$and: [subscription.scopeQuery(), {author: Meteor.userId()}]}).count();
Related projects

This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.