MongoClient.connect(url,{ useNewUrlParser: true }, function(err, db) {
if (err) throw err;
var dbo = db.db(db_name);
dbo.collection("assets").aggregate([
{ $lookup:
{
from: 'employee',
localField: 'assign_to',
foreignField: 'employee_id',
as: 'employee_details'
}
}
]).sort({_id:-1}).toArray(function(err, result) {
if (err) throw err;
res.status(200).json({'return_data': result });
db.close();
});
});
我想从员工详细信息中获取员工姓名
答案 0 :(得分:1)
执行此操作的基本方法之一是使用嵌套循环。
for (let i = 0; i < re.length; ++i){
//Resolves to true if you are in the inner array
if(re[i].inventory_docs){
inventory=re[i].inventory_docs;
//Get the value out using object notation
for( let j = 0; j < inventory.length; ++j)
console.log(inventory[j].sku);
}
}