So I have a few mongoose schema's defined.
var partSchema = mongoose.Schema({
name: String,
system: String,
team: Array,
quantity: Number,
});
var part = mongoose.model('part', partSchema);
var peopleSchema = mongoose.Schema({
name: String,
pass: String,
role: String,
parts: Array
});
var people = mongoose.model('people', peopleSchema);
And I want to send queries based on these schemas, and more, to the user. As such...
app.get('/', function(req, res){
people.find(function(err, persons){
if (err) return handleError(err);
console.log(persons);
parts.find(function(err, things){
res.render('in', { user: req.session.user, people:persons, parts:things });
});
});
});
To remain asynchronous, I would have to nest these calls, right? And I cant nest these calls, because "parts" is no longer defined. I'm wondering if I could do this, and how would I do it? Sorry if it's a noob question, but I've looked this up for days, and haven't seemed to find a solution. Thanks!
The variable name of your 'part' model is part, not parts. So it should be:
app.get('/', function(req, res){
people.find(function(err, persons){
if (err) return handleError(err);
console.log(persons);
part.find(function(err, things){ // <-- Changed on this line
res.render('in', {user: req.session.user, people:persons, parts:things});
});
});
});