Last active
August 29, 2015 13:56
-
-
Save PistachioPony/9099975 to your computer and use it in GitHub Desktop.
Get information from the req.contents including from an Array
This file contains 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
//Pull out the item with that id add it to the req.contents hash then go to next function... | |
var mariaItem = function (req, res, next) { | |
Item.findOne({ _id: "5099803df3f4948bd2f98391"}, function (err, result){ | |
//res.json(result); | |
//var firstOne = res.json(result); | |
//{ field: { $in: [<value1>, <value2>, ... <valueN> ] } } | |
//Group.find({_id: {$in: req.contents.item.groups}}, function (err, groups) { | |
req.contents = {}; | |
req.contents.result = result; | |
next(); | |
}); | |
}; | |
//Out of te Users, find the one whose id matches the sellerId that is in the req hash (req.contents.result.seller.sellerId) | |
//And add that result to the req hash and then go to the next function... | |
var mariaS = function (req, res, next) { | |
User.findOne({_id: req.contents.result.seller.sellerId}, function (err, result){ | |
req.contents.seller = result; | |
next(); | |
//res.json(req.contents); | |
}); | |
}; | |
//Out of the Group find the group id the matches from the array groups that is in the req.contents etc hash add it | |
//And show everything that is in the req.contents now (in json) | |
var mariaG = function (req, res, next) { | |
Group.find({_id: {$in: req.contents.result.groups}}, function (err, result){ | |
req.contents.groups = result; | |
res.json(req.contents); | |
}); | |
}; | |
app.get('/maria/item', | |
mariaItem, | |
//mariaTwo, | |
mariaS, | |
mariaG | |
// mariaShowIt | |
); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment