Created
June 19, 2014 21:16
-
-
Save artcommacode/23b9a415a27e37e6f0b1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Page is the returned mongoose Model for 'Page' | |
Page | |
// finding all pages that have isPublished set to true | |
.find({isPublished: true}) | |
// populating the sub-documents 'album' from the 'Album' Model | |
.populate({ | |
path: 'album' | |
}) | |
// execute the query | |
.exec(function (error, pages) { | |
// if it errors just return right out of there | |
if (error) return callback(error); | |
// else callback node style (first value error (which is null), second value the result) | |
// filter the pages to only the ones we need | |
callback(null, pages.filter(function (page) { | |
// filter accepts 'true' for anything you want to keep and 'false' for not | |
// if there's no album then return false (reject) | |
// if the album has a url of 'shop' or 'events' then return true (keep) | |
// otherwise return false (reject) | |
return !page.album ? | |
false : | |
page.album.url === 'shop' || page.album.url === 'events'; | |
})); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment