MongoDB // Nodemon Crash我在Postman中发布
2020-05-17
289
当我运行 nodemon file.js 时,它显示此内容(cmd):
(node:23816) DeprecationWarning: current URL string parser is deprecated, and will be removed in a future version. To use the new parser, pass option { useNewUrlParser: true } to MongoClient.connect.
(node:23816) DeprecationWarning: current Server Discovery and Monitoring engine is deprecated, and will be removed in a future version. To use the new Server Discover and Monitoring engine, pass option { useUnifiedTopology: true } to the MongoClient constructor.
And then when i POST in Postman show this (cmd) :
events.js:287
throw er; // Unhandled 'error' event
^
ReferenceError: response is not defined
at D:\Desktop\swag-shop-api\server.js:21:7
at D:\Desktop\swag-shop-api\node_modules\mongoose\lib\model.js:4889:16
at D:\Desktop\swag-shop-api\node_modules\mongoose\lib\helpers\promiseOrCallback.js:24:16
at D:\Desktop\swag-shop-api\node_modules\mongoose\lib\model.js:4912:21
at model.<anonymous> (D:\Desktop\swag-shop-api\node_modules\mongoose\lib\model.js:493:7)
at D:\Desktop\swag-shop-api\node_modules\kareem\index.js:315:21
at next (D:\Desktop\swag-shop-api\node_modules\kareem\index.js:209:27)
at D:\Desktop\swag-shop-api\node_modules\kareem\index.js:182:9
at D:\Desktop\swag-shop-api\node_modules\kareem\index.js:507:38
at processTicksAndRejections (internal/process/task_queues.js:79:11)
Emitted 'error' event on Function instance at:
at D:\Desktop\swag-shop-api\node_modules\mongoose\lib\model.js:4891:13
at D:\Desktop\swag-shop-api\node_modules\mongoose\lib\helpers\promiseOrCallback.js:24:16
[... lines matching original stack trace ...]
at processTicksAndRejections (internal/process/task_queues.js:79:11)
[nodemon] app crashed - waiting for file changes before starting...
但是当我执行 db.products.find({}) 时,它显示我从 postman 发布的所有信息
请问有人可以帮帮我吗...
2个回答
如果您需要一些指导来在 mongodb 中的集合中列出您的文档,只需使用此代码作为起点:
在第 13 行,您必须将代码更改为:
app.post("/product", function(request, response) {
参数的名称必须是
response
。
Danizavtz
2020-05-18
解决方案:
第 5 行:var db = mongoose.connect("mongodb://localhost/swag-shop", { useNewUrlParser: true, useUnifiedTopology: true, });
第 16 行:app.post("/product", function (request, response) {
感谢:@Danizavts 和 @VedantBang。
Android Dev
2020-05-18