Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/versolearning/find-from-publication
Enable finding all documents that have been published by a given publication
https://github.com/versolearning/find-from-publication
Last synced: 3 months ago
JSON representation
Enable finding all documents that have been published by a given publication
- Host: GitHub
- URL: https://github.com/versolearning/find-from-publication
- Owner: versolearning
- Created: 2014-09-25T05:29:41.000Z (about 10 years ago)
- Default Branch: master
- Last Pushed: 2019-05-28T13:13:40.000Z (over 5 years ago)
- Last Synced: 2024-06-19T03:03:08.879Z (5 months ago)
- Language: JavaScript
- Size: 10.7 KB
- Stars: 45
- Watchers: 6
- Forks: 7
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
- awesome-meteor - percolate:find-from-publication - Enable finding all documents that have been published by a given publication. (Search, sort and paginate)
README
# Find From Publication
Find from publication works around a limitation in Meteor core- there's no way to determine which records, client side, have resulted from a given subscription.
This package works around this issue by tracking the subscription's published document in a special, hidden _metadata_ collection.
### API
#### Server Side
To publish a tracked set of documents, simply call:``` js
import { FindFromPublication } from 'meteor/percolate:find-from-publication';FindFromPublication.publish(name, publisherFn)
```This behaves just as `Meteor.publish`, in that you can call `added/removed/changed/ready` or simply return (a set of) cursor(s).
#### Client Side
To get the documents published by a given named publication in a given collection, simply call:``` js
Collection.findFromPublication(name, query, options);
```
or
``` js
Collection.findOneFromPublication(name, query, options);
```#### Example
``` js
import { Meteor } from 'meteor/meteor';
import { Mongo } from 'meteor/mongo';
import { FindFromPublication } from 'meteor/percolate:find-from-publication';const Posts = new Mongo.Collection('posts');
if (Meteor.isServer) {
FindFromPublication.publish('allPosts', function() {
return Posts.find();
});
}if (Meteor.isClient) {
Meteor.subscribe('allPosts');
// in a helper, etc
const postsCursor = Posts.findFromPublication('allPosts');
const randomPost = Posts.findOneFromPublication('allPosts', { _id: 'x45ebOafda' });
}
```#### Sorting
By default, the documents client-side will be sorted by the order they were added.
### How it works
When you call `added`, we simply add a record to the `subscriptionMetadata` client-only collection. It has the form:
``` js
{
_id: 'a-unique-id-for-this-record',
collectionName: 'posts',
documentId: 'the-real-document-id',
publicationName: 'allPosts',
rank: 7 // a globally increasing rank over all publications.
}
```## License
MIT. (c) Percolate Studio, maintained by Tom Coleman (@tmeasday).
Find From Publication was developed as part of the [Verso](versoapp.com) project.