Skip to content

Instantly share code, notes, and snippets.

@otang
Created August 15, 2013 21:14
Show Gist options
  • Save otang/6244975 to your computer and use it in GitHub Desktop.
Save otang/6244975 to your computer and use it in GitHub Desktop.
models.Page.find({ parent_id: null }).sort({ name: 'asc' }).exec (err, pages) ->
for page, i in pages
models.Page.find({ parent_id: page._id }).sort({ name: 'asc' }).exec (err, children) ->
pages[i].children = children
# return pages when all the queries are done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment