Using http query string as a database object node.js/express

后端 未结 1 1458
猫巷女王i
猫巷女王i 2021-01-23 23:17

Experimenting with node.js / express / mongodb.

I\'m using

http://localhost:3000/models/save?model={\"name\":\"blah blah blah\"}

to pass a test JSON obj

相关标签:
1条回答
  • 2021-01-23 23:55

    Please try the following:

    var model = JSON.parse(req.query.model);
    

    instead of the line

    var model = req.query.model;
    

    JSON.parse method parses JSON string representation (which in your case is model request query parameter) and returns Javascript object which you can then use in your insert process.

    I hope it helps some way.

    0 讨论(0)
提交回复
热议问题