Home > front end >  Nodejs - same line statements, variable data inconsistency is why
Nodejs - same line statements, variable data inconsistency is why

Time:09-19

As shown in figure.




Code:
 
The router. The get ('/allmachines' auth required, (the req, res, next)=& gt; {
Var count
Those countDocuments (). Then ((c)=& gt; {
Count=c
})

Var p=new Promise ((resolve, reject)=& gt; {
Those. The find (). Then ((result)=& gt; {
Resolve (result)
})
})

P.t hen ((result)=& gt; {
The return of new Promise ((resolve, reject)=& gt; {
Result. The forEach (element=& gt; {
Users. The find ({_id: element. Ownerid}). Then ((result2)=& gt; {
Element. Owneremail=result2 [0]. Email
})
Resolve (result)
})
})

}). Then ((result)=& gt; {
The console. The log (result [0]. Owneremail + "aaaaaaaaaa", result)
Return res. Json ({' count ': the count, "status" : 200,' data, the result, the 'code' : 0})
})
});

module.exports=router;
  • Related