【发布时间】:2019-06-09 19:26:38
【问题描述】:
我想将一些数据发布到我的 mongo 数据库。
但是架构的结构让我对实现感到困惑。
这是架构:
var GraphSchema = new Schema({
nodes: [{id: String}],
links: [{source:String, target: String}]
});
这是我迄今为止尝试过的,但它似乎不起作用:
router.post('/graphs', (req, res) => {
const graph = new Graph();
graph.nodes = [{id: req.body.nodes.id}];
graph.links = [{source: req.body.source, target: req.body.target}];
graph.save((err) => {
if(err) return res.status(500).json({ message: 'internal error' })
res.json({ message: 'saved...' })
})
});
例如,我想实现这样的最终结果:
{
"data": [
{
"nodes": [
{
"id": "root"
},
{
"id": "input"
},
{
"id": "component"
}
],
"links": [
{
"source": "component",
"target": "root"
}
]
}
]
}
我正在使用 Postman 测试操作 关于如何继续,我陷入了死胡同,所以我希望你能给我一些提示!
【问题讨论】:
标签: mongodb post postman mongoose-schema