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

后端 未结 1 1456
猫巷女王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)
提交回复
热议问题