그냥 nodejs/mongoose를 사용하기 시작했는데 고전적인 비동기 문제가 있다고 생각합니다. 누군가이 비동기 문제를 해결하는 방법을 안내해 줄 수 있습니까?비동기 라이브러리가있는 회 돌이에서 몽구스 비동기 호출
이 함수는 "getAreasRoot"이며 내부에는 다른 비동기 함수의 결과를 채우는 루프가 있습니다. 비동기 라이브러리로 어떻게 해결할 수 있습니까?
areaSchema.statics.getAreasRoot = function(cb: any) {
let self = this;
return self.model("Area").find({ parentId: null }, function(err: any, docs: any){
docs.forEach(function(doc: any){
doc.name = "Hi " + doc.name;
doc.children = self.model("Area").getAreasChildren(doc._id, function(err: any, docs: any){});
})
cb(err, docs);
});
};
areaSchema.statics.getAreasChildren = function(id: any, cb: any) {
return this.model("Area").find({ parentId: null }).exec(cb);
}
[for 루프 내부에서 몽구스 기능을 어떻게 사용할 수 있습니까?] (https://stackoverflow.com/questions/44569770/how-can-i-use-mongoose-functions-inside-a-for- 루프) –
@KevinB OP가 async.js와 함께 사용하는 방법을 묻는다면 실제로는 중복되지 않습니다. 제공된 답변 중 어느 것도 async.js를 사용하지 않습니다. – Mikey