VOOZH about

URL: https://gist.github.com/cmalven/7469244

⇱ Joining collections in Meteor/Mongo · GitHub


Skip to content
Sign in Sign up

Instantly share code, notes, and snippets.

Joining collections in Meteor/Mongo
# In an Iron Router Route (requires that the below publication is also set up)
# =====================================
Router.configure
layoutTemplate: 'layout'
loadingTemplate: 'loading'
Router.map ->
@route 'member_show',
path: '/members/:_id',
template: 'members_show',
waitOn: ->
return [
Meteor.subscribe('members'),
Meteor.subscribe('documents', @params._id)
]
data: ->
return {
member: Members.findOne({_id: @params._id})
documents: Documents.find()
}
# In typical publish
# =====================================
Meteor.publish 'documents', (member_id) ->
return Documents.find() unless member_id?
member = Members.findOne
_id: member_id
return Documents.find
_id: {$in: member.documents}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.