使用nodejs和mongodb调用REST API

时间:2018-05-02 13:10:38

标签: node.js mongodb rest api

我是node.js的新手。以下是我的GET请求:

let $doc := doc("mondial.xml")/mondial
let $lakes := $doc/lake
let $islands := $doc/island

let $lakesWithIslands := (
  for $l in $lakes
  let $lLong := $l/data(longitude)
  let $lLat := $l/data(latitude)
  let $lArea := $l/data(area)
    for $i in $islands
     let $iLong := $i/data(longitude)
     let $iLat := $i/data(latitude)
     let $iArea := $i/data(area)
     where (something)
  return $l
)

return $lakesWithIslands

我在POSTMAN中遇到请求时收到router.get('/EPODS/Product/:id?', function(req, res) { if(req.params.id){ var inputIdObj={'ProductEBM.DataArea.Product.ProductGroupID': req.params.id}; } else { res.status(500).json({ "Error": "No input given Try give something or Check for the case sensitive in the input query fields" }); res.end(); return; } db.collection('Product').findOne(inputIdObj,function(err, doc) { if (err) { console.log("No record found for the given input"); res.end("No record found for the input data- Please check again"); } else { res.send(doc); } }); }); 值,但查询在MONGODB中有效。

请帮忙! 在此先感谢。

1 个答案:

答案 0 :(得分:0)

当您获得GET请求的参数时,您将获得String格式的ID,如果您使用ObjectID,则无法使用该格式。首先,将您的参数转换为ObjectID(您可以使用java.time导入对象),然后创建:require('mongodb').ObjectID