U kunt elke findOne
. inpakken functioneer in de belofte en gebruik await
van Babel. In dit geval kan uw code er als volgt uitzien:
let office = await new Promise((resolve, reject) => {
Office.findOne({ geolocation: origin._id}, function(err, office){
if (err) reject(err)
resolve(office)
});
let company = await new Promise((resolve, reject) => {
Company.findOne({ _id: office.company }, function(err, company){
if (err) reject(err)
resolve(company)
});
... and so on
Of misschien wil je lezen over de bevolking in MongoDB:http://mongoosejs.com/docs/populate .html