我正在Angular中读取JSON文件,从中提取部分内容,然后将其保存到mongodb中。发布请求运行两次,而我只调用一次。
因此,结果在集合中,我两次都有所有条目!
这里是我发送请求的角度:
WhileReadingRecords;
DateVar Array Holidays;
DateVar Target:=Date({DATE_RECEIVED});
NumberVar Add;
NumberVar Added := 0;
if {METADATA_REPOSITORY.FIELD_VARCHAR_16} = "Test_1" then
NumberVar Add = 28;
WHILE Added < Add
Do (target := target +1;
if dayofweek (target) in 2 to 6 and not (target in holidays)
then Added:=Added+1
else Added:=Added);
Target
else if {ORDTASK.TESTGROUPNAME} = "Test_2" then
NumberVar Add =14;
WHILE Added < Add
Do (target := target +1;
if dayofweek (target) in 2 to 6 and not (target in holidays)
then Added:=Added+1
else Added:=Added);
Target
//else
NumberVar Add = DateAdd("d", Tonumber({TESTS.DURATION}), {CENTRALRECEIVING.DATE_RECEIVED});
WHILE Added < Add
Do (target := target +1;
if dayofweek (target) in 2 to 6 and not (target in holidays)
then Added:=Added+1
else Added:=Added);
Target
这是保存功能以调用服务
getNVD() {
this.readJsonService.getNVDJSON().subscribe(response=>{
if(response){
for(let i=0; i < response['CVE_Items'].length; i++)
{
this.INVDStructure.push({
ID: response['CVE_Items'][i]['cve'].CVE_data_meta.ID,
affects: response['CVE_Items'][i].cve.affects,
impact: response['CVE_Items'][i].impact
})
}
this.SaveNVD();
}//if
else {console.log("error in getting the NVD ");}
});
}
这是服务:
SaveNVD(){
this.submitService.createNVDDB(this.INVDStructure).subscribe(response => {
if (response) {
console.log(response.body['message'] );
}
});
}
这是发布请求:
createNVDDB(s):Observable<HttpResponse<INVDStructure>> {
return this.http.post<INVDStructure>(this.domain+'/nvdGenerate',s, {observe: 'response'})
}
如所见,我叫过一次。我不知道为什么要运行两次。我们将不胜感激。