Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/maxnowack/meteor-querychain

This package enables chaining mongo cursors for Meteor
https://github.com/maxnowack/meteor-querychain

Last synced: 4 days ago
JSON representation

This package enables chaining mongo cursors for Meteor

Awesome Lists containing this project

README

        

# QueryChain
This package enables chaining mongo cursors like this:
````javascript
Posts.find().fromMax().withComments()
````

## Installation
````
meteor add maxnowack:querychain
````

## Usage

````javascript
Posts = new Mongo.Collection('posts');

// add a chain method
QueryChain.add({
withComments: { // name of the method
query: { // a mongo query
comments: {
$gt: 0
}
}
}
});

// it's also possible, to define a function to provide a query
QueryChain.add({
from: {
query: function(name){
return {
author: name
}
}
}
});

Posts.find().withComments() // returns a cursor for the query speficied above

// you can also chain multiple methods:
QueryChain.add({
fromMax: {
query: {
author: 'Max'
}
}
});

Posts.find().fromMax().withComments()

// or limit methods to specific collections
QueryChain.add({
notFromMax: {
collection: Posts
query: {
author: {
$ne: 'Max'
}
}
}
});
````