Javascript 对内部地图的承诺已经失效

Javascript 对内部地图的承诺已经失效,javascript,node.js,mongoose,promise,es6-promise,Javascript,Node.js,Mongoose,Promise,Es6 Promise,我希望你能帮助我。。。我使用multer上传一个文件,基本上我想用文件中的所有对象发布到我的数据库。在Postman中,文件位于正文中的表单数据区 下面的.post方法只是给您一个想法,我将在后面向您展示importFile函数,即读取并保存到数据库的函数,在这里我得到了实际的问题 var{Router}=require('express'); var路由器=路由器(); var importer=require('../../services/importer'); var multer=需要

我希望你能帮助我。。。我使用multer上传一个文件,基本上我想用文件中的所有对象发布到我的数据库。在Postman中,文件位于正文中的表单数据区

下面的.post方法只是给您一个想法,我将在后面向您展示importFile函数,即读取并保存到数据库的函数,在这里我得到了实际的问题

var{Router}=require('express');
var路由器=路由器();
var importer=require('../../services/importer');
var multer=需要('multer');
var upload=multer();
module.exports=(应用程序)=>{
应用程序使用('/importer',路由器);
router.post('/',upload.single('file'),importer.importFile,function(req,res){
返回res.json({消息:“文件已成功导入”。});
});
};
现在是importer.js,它负责读取文件并使用mongoose将其数据保存到DB

const importFile=async(req、res、next)=>{
var jsonConverted=JSON.parse(convert.xml2json(req.file.buffer.toString(),{compact:true,spaces:4,alwaysChildren:true}));
var nodesDictionary={};
var pathNodesArray=[];
var linePathsArray=[];
var pathsDictionary={};
等待(jsonConverted.GlDocumentInfo.world.GlDocument.GlDocumentNetwork.Network.Nodes.Node.map)(异步节点=>{
var newNode=新节点();
newNode.key=node.\u attributes.key;
newNode.name=node.\u attributes.name;
newNode.latitude=node.\u attributes.latitude;
newNode.longitude=node.\u attributes.longitude;
newNode.shortName=node.\u attributes.shortName;
newNode.isDepot=node.\u attributes.isDepot.toString().toLowerCase();
newNode.isReliefPoint=node.\u attributes.isReliefPoint.toString().toLowerCase();
nodesDictionary[newNode.key]=newNode.\u id;
newNode.save(函数(err){
如果(错误){
返回下一个(错误);
}
});
}));
等待Promise.all(jsonConverted.GlDocumentInfo.world.GlDocument.GlDocumentNetwork.Network.Path.Path.map(异步路径=>{
路径节点阵列=[];
等待Promise.all(path.PathNodes.PathNode.map)(异步PathNode=>{
var newPathNode=newPathNode();
newPathNode.key=pathNode.\u attributes.key;
newPathNode.node=NodeDictionary[pathNode.\u attributes.node];
newPathNode.duration=pathNode.\u attributes.duration;
newPathNode.distance=pathNode.\u attributes.distance;
PathNodeArray.push(newPathNode.\u id);
newPathNode.save(函数(错误){
如果(错误){
返回下一个(错误);
}
});
})).然后(()=>{
var newPath=新路径();
newPath.key=path.\u attributes.key;
newPath.isEmpty=path.\u attributes.isEmpty.toString().toLowerCase();
分配(newPath.pathNodes、pathNodesArray);
pathsDictionary[newPath.key]=新路径。\u id;
newPath.save(函数(err){
如果(错误){
返回下一个(错误);
}
});
});
}))。然后(异步()=>{
等待(jsonConverted.GlDocumentInfo.world.GlDocument.GlDocumentNetwork.Network.Lines.Line.map)(异步行=>{
linePathsArray=[];
等待Promise.all(line.LinePath.LinePath.map)(异步LinePath=>{
var newLinePath=newLinePath();
newLinePath.key=linePath.\u attributes.key;
newLinePath.path=pathsDictionary[linePath.\u attributes.path];
newLinePath.orientation=linePath.\u attributes.orientation;
linePathsArray.push(newLinePath.\u id);
newLinePath.save(函数(err){
如果(错误){
返回下一个(错误);
}
});
})).然后(()=>{
var newLine=新行();
newLine.key=line.\u attributes.key;
newLine.name=line.\u attributes.name;
newLine.color=line.\u attributes.color.slice(4,line.\u attributes.color.length-1).split(',');
Object.assign(newLine.linepath、linePathsArray);
换行。保存(函数(错误){
如果(错误){
返回下一个(错误);
}
});
});
}));
});
返回next();
};
module.exports.importFile=importFile;
本质上,我需要首先读取节点,然后读取每条路径的pathnodes,以及它们各自的末端路径,然后读取每条线的LinePath,以及它们各自的末端线。该文件是一个XML格式的巨大.glx文件,这就是为什么在选择和映射我真正感兴趣的对象(如节点、线路径等)之前,我基本上必须先执行jsonConverted.GlDocumentInfo.world.GlDocument.GlDocumentNetwork.Network。节点读取很好,但问题在于承诺之后,我需要映射所有路径,但每个路径都有一个需要添加到该路径的PathNodes列表。问题是数据库中保存的是最后2个pathNode ID,而不是该路径的实际pathNodes

为了给您提供上下文,这里是.glx文件的一部分:

<Paths>
                    <Path key="Path:1" IsEmpty="False">
                        <PathNodes>
                            <PathNode key="PathNode:1" Node="Node:1" />
                            <PathNode key="PathNode:2" Node="Node:15" Duration="600" Distance="5000" />
                            <PathNode key="PathNode:3" Node="Node:13" Duration="360" Distance="3200" />
                            <PathNode key="PathNode:4" Node="Node:4" Duration="360" Distance="3000" />
                            <PathNode key="PathNode:5" Node="Node:14" Duration="540" Distance="4500" />
                        </PathNodes>
                    </Path>
                    <Path key="Path:3" IsEmpty="False">
                        <PathNodes>
                            <PathNode key="PathNode:11" Node="Node:14" />
                            <PathNode key="PathNode:12" Node="Node:4" Duration="540" Distance="4500" />
                            <PathNode key="PathNode:13" Node="Node:13" Duration="360" Distance="3000" />
                            <PathNode key="PathNode:14" Node="Node:15" Duration="360" Distance="3200" />
                            <PathNode key="PathNode:15" Node="Node:1" Duration="600" Distance="5000" />
                        </PathNodes>
                    </Path>
(...)
</Paths>

(...)
因此,基本上每个路径都有一个pathNodes列表,正如您所看到的,然而,只有2AR