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
User | Most Recent Commit | # Commits |
---|
Other Committers
User | Most Recent Commit | # Commits |
---|
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.
or add peerlibrary:subscription-scope
The subscription handle returned from Meteor.subscribe
contain a new method:
scopeQuery()
? returns a query which limits collection's documents only to this subscriptionLimiting 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:
enableScope()
? when enabled, for subscriptions to this publish endpoint, clients can use scopeQuery()
to limit queries only to the subscriptionIf 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();