Meteor-Community-Packages / meteor-collection-hooks

Meteor Collection Hooks
https://atmospherejs.com/matb33/collection-hooks
MIT License
657 stars 92 forks source link

Merge 2 collections with before.find and before.findOne hooks #147

Closed joaopiopedreira closed 9 years ago

joaopiopedreira commented 9 years ago

Hi @matb33 ,

I have 2 collections (let's say coll an collStatic). coll is a standard meteor collection. collStatic is a client-only collection. They both have the same data schema.

When I run a find() or findOne() on "coll", I'd like to retrieve data from both "coll" and "collStatic".

Is this possible with collection-hooks?

Thanks.

matb33 commented 9 years ago

It's probably possible... I assume that in your before.find you'd have to run the query against both collections, iterate over both result sets and push the docs to a new cursor that you then return instead.

joaopiopedreira commented 9 years ago

Hi,

I've tried that, but didn't succeed in returning from the before.find function.

Something like; Collection1.before.find(function(...){ Return Collection1.find().fetch().concat(Collection2.find().fetch() })

But that doesn't work...

Have any ideas?

Many thanks,

João Pio Pedreira /// Sent from a mobile device ///

On 1 Sep 2015, at 19:44, Mathieu Bouchard notifications@github.com wrote:

It's probably possible... I assume that in your before.find you'd have to run the query against both collections, iterate over both result sets and push the docs to a new cursor that you then return instead.

— Reply to this email directly or view it on GitHub.

matb33 commented 9 years ago

My apologies: before.find doesn't allow you to return an alternate cursor, it only allows you to modify the arguments by reference