Mongo db เกิดข้อผิดพลาด-จบประเด็นทำงาน-ข้อมูลของมันไม่ช่วยในฐานข้อมูล

0

คำถาม

ในขณะที่กำลังเช็คข้อ endpoint ใช้โพสต์วิธีการอยู่ในบุรุษไปรษณีย์มีข้อผิดพลาด

.ซองแฟ้มกับพอร์ต,MONGO_URI และ mongoose การเชื่อมต่อจะถูกตั้งขึ้นอย่างเหมาะสมและกำลังกอไม่มีข้อผิดพลาด

รหัสในของฉัน app.js

const express = require('express')
require('./db/db')
const dotenv = require('dotenv')
const app = express()
const mongoose = require('mongoose')

dotenv.config({ path: 'config.env' })
const PORT = process.env.PORT

const User = require('./model/user')

app.get('/', (req,res)=>{
    res.send('Hello')
})

app.post('/create-user', async(req, res)=>{
    const user = await User({ 
        fullname: 'John5 Doe', 
        email:'[email protected]', 
        password:'12345'
    });
    await user.save();
    res.json(user);
})

app.listen(PORT, () =>{
    console.log(`app is running on port ${PORT}`)
})

แต่ข้อมูลมันไม่ช่วยใน MongoDB กฐานข้อมูลเหมือนกัน เท่าที่ผมตรวจ endpoint ในบุรุษไปรษณีย์และปรับปรุงคลังสื่ออยู่ใน mongo db มันเป็นการแสดงหน้าเว็บนี้enter image description here

ยังไงฉันซ่อมได้??

mongodb mongoose node.js
2021-11-24 05:36:40
1

คำตอบที่ดีที่สุด

1
app.post('/create-user', async(req, res)=>{
const user = new User({ 
    fullname: 'John5 Doe', 
    email:'[email protected]', 
    password:'12345'
});
await user.save();
res.json(user); })

มันควรจะเป็นคนใหม่ของผู้ใช้ไม่รอคำสั่งของผู้ใช้. ก็คุณสามารถใช้พยายามจับอยู่ในบล็อกของคุณฟังก์ชันดังนั้นคุณจะต้องรู้จักข้อผิดพลาดปูมบันทึก.

2021-11-24 06:17:49

ในภาษาอื่นๆ

หน้านี้อยู่ในภาษาอื่นๆ

Русский
..................................................................................................................
Italiano
..................................................................................................................
Polski
..................................................................................................................
Română
..................................................................................................................
한국어
..................................................................................................................
हिन्दी
..................................................................................................................
Français
..................................................................................................................
Türk
..................................................................................................................
Česk
..................................................................................................................
Português
..................................................................................................................
中文
..................................................................................................................
Español
..................................................................................................................
Slovenský
..................................................................................................................