All Projects → peerlibrary → meteor-reactive-mongo

peerlibrary / meteor-reactive-mongo

Licence: BSD-3-Clause license
Reactive server-side MongoDB queries

Programming Languages

javascript
184084 projects - #8 most used programming language
coffeescript
4710 projects

Projects that are alternatives of or similar to meteor-reactive-mongo

Meteor-logger-file
🔖 Meteor Logging: Store application log messages into file (FS)
Stars: ✭ 24 (+71.43%)
Mutual labels:  meteor, meteor-package
Meteor Reactive Publish
Reactive publish endpoints
Stars: ✭ 123 (+778.57%)
Mutual labels:  meteor, meteor-package
Ostrio Neo4jdriver
Most advanced and efficient Neo4j REST API Driver, with support of https and GrapheneDB
Stars: ✭ 55 (+292.86%)
Mutual labels:  meteor, meteor-package
meteor-two-factor
🔐 Two factor authentication package for accounts-password
Stars: ✭ 80 (+471.43%)
Mutual labels:  meteor, meteor-package
Client-Storage
🗄 Bulletproof persistent Client storage, works with disabled Cookies and/or localStorage
Stars: ✭ 15 (+7.14%)
Mutual labels:  meteor, meteor-package
Meteor Files
🚀 Upload files via DDP or HTTP to ☄️ Meteor server FS, AWS, GridFS, DropBox or Google Drive. Fast, secure and robust.
Stars: ✭ 1,033 (+7278.57%)
Mutual labels:  meteor, meteor-package
Meteor Transactions
App level transactions for Meteor + Mongo
Stars: ✭ 115 (+721.43%)
Mutual labels:  meteor, meteor-package
Vue Meteor
🌠 Vue first-class integration in Meteor
Stars: ✭ 893 (+6278.57%)
Mutual labels:  meteor, meteor-package
blaze-integration
Vue integration with Meteor's Blaze rendering engine.
Stars: ✭ 24 (+71.43%)
Mutual labels:  meteor, meteor-package
Meteor Google Maps
🗺 Meteor package for the Google Maps Javascript API v3
Stars: ✭ 198 (+1314.29%)
Mutual labels:  meteor, meteor-package
Autocms
AutoCms is a simple solution for your Meteor.js app
Stars: ✭ 34 (+142.86%)
Mutual labels:  meteor, meteor-package
Meteor-Template-helpers
Template helpers for Session, logical operations and debug
Stars: ✭ 35 (+150%)
Mutual labels:  meteor, meteor-package
Ostrio Analytics
📊 Visitor's analytics tracking code for ostr.io service
Stars: ✭ 9 (-35.71%)
Mutual labels:  meteor, meteor-package
Meteor-Cookies
🍪 Isomorphic bulletproof cookie functions for client and server
Stars: ✭ 41 (+192.86%)
Mutual labels:  meteor, meteor-package
Mongol Meteor Explore Minimongo Devtools
In-App MongoDB Editor for Meteor (Meteor DevTools)
Stars: ✭ 846 (+5942.86%)
Mutual labels:  meteor, meteor-package
Meteor Comments Ui
Simple templates for comment functionality in your Meteor App
Stars: ✭ 78 (+457.14%)
Mutual labels:  meteor, meteor-package
Blaze
🔥 Meteor Blaze is a powerful library for creating live-updating user interfaces
Stars: ✭ 474 (+3285.71%)
Mutual labels:  meteor, meteor-package
Meteor Collection Helpers
⚙️ Meteor package that allows you to define helpers on your collections
Stars: ✭ 504 (+3500%)
Mutual labels:  meteor, meteor-package
Meteor Peerdb
Reactive database layer with references, generators, triggers, migrations, etc.
Stars: ✭ 128 (+814.29%)
Mutual labels:  meteor, meteor-package
meteor-computed-field
Reactively computed field for Meteor
Stars: ✭ 18 (+28.57%)
Mutual labels:  meteor, meteor-package

reactive-mongo

Meteor smart package which provides a fully reactive server-side MongoDB queries. This allows them to be used in server-side autorun, together with other fibers-enabled synchronous (blocking) code.

Adding this package to your Meteor application will make all MongoDB queries reactive by default (you can still specify reactive: false to queries to disable reactivity for a specific query, or use Tracker.nonreactive). It will also automatically enable server-side autorun. All this might break some existing server-side code which might not expect to be reactive. Inspect locations where your code or packages you are using already (before using this package) call Tracker.autorun on the server. In most cases this occurs only in the code which is shared between client and server.

Server side only.

Installation

meteor add peerlibrary:reactive-mongo

Ordered vs. unordered cursors

In Meteor, there's a concept of ordered cursors. If a cursor is ordered, then when the order of the documents in the result set changes, the reactive computation will be invalidated and it be will re-run.

By default, this package will use an ordered cursor if a sort option is present in the query. If no sort option is specified, it will use an unordered cursor.

To override the default functionality, you can explicitly force or un-force the type of a cursor by passing an ordered option to your find query:

// Server-side code.

// Will use an ordered cursor since sort option is present.
Tracker.autorun(() => {
  Posts.find({topic: 'news'}, {sort: {name: 1}}).fetch();
});

// Will use an unordered cursor since no sort option is present.
Tracker.autorun(() => {
  Posts.find({topic: 'news'}).fetch();
});

// Will not use an ordered cursor since it is explicitly disabled.
Tracker.autorun(() => {
  Posts.find({topic: 'news'}, {sort: {name: 1}, ordered: false}).fetch();
});

// Will use an ordered cursor since it is explicitly enabled.
Tracker.autorun(() => {
  Posts.find({topic: 'news'}, {ordered: true}).fetch();
});

You wan to choose the cursor so that invalidations happen when and only when you want them to happen.

Reactive queries and polling vs. oplog

A common use case for server-side reactive computations is using a findOne to do a reactive join. Meteor's server-side findOne is a find(selector, {limit: 1}).fetch()[0] under the hood. Because Meteor oplog does not support limit without sort, calling Collection.findOne(someId) in a server-side reactive computation will default to using polling.

If you would like queries inside a server-side reactive computation to use oplog, you will need to specify a sort option for your findOne query and pass ordered: false to use an unordered cursor:

// Server-side code.

// Will use oplog since it has sort, limit, and is unordered.
Tracker.autorun(() => {
  Collection.findOne(someId, {sort: {_id: 1}, ordered: false});
});

// Will use polling because a limit (from findOne) but no sort is specified.
Tracker.autorun(() => {
  Collection.findOne(someId);
});

Acknowledgments

This package is based on the great work by Diggory Blake who made the first implementation.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].