Skip to content

Instantly share code, notes, and snippets.

@cmalven
Last active March 2, 2026 05:18
Show Gist options
  • Select an option

  • Save cmalven/7469244 to your computer and use it in GitHub Desktop.

Select an option

Save cmalven/7469244 to your computer and use it in GitHub Desktop.
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}
@nisarllc206-sys
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment