Node.JS /Mongo ยังไม่บันทึกข้อมูลสมบูรณ์

0

คำถาม

ฉันสร้างแรกรูปแบบชุดสีและอีกหนึ่ง(2 ตาราง)ใน MongoDB เพื่อนบ้าน 2 แยกข้อมูล ตอนนี้คนแรกทำงานได้โดยไม่มีการท้าทายนะแต่คำที่สองชุดรูปแบบควรจะเป็นคนที่บ้านของผู้ใช้ข้อมูล

ตอนนี้ฉันมีปัญหาเรื่องโดนข้อมูลของผู้ใช้. ฉันไม่เหมือนจะเข้าใจปัญหาคืออะไร

ครูปแบบชุดสีดูเหมือนนี้

var db = require('../database');
var mongoose = require('mongoose');
var Schema = mongoose.Schema;

var SubscriptionSchema = new Schema({
    company_name : String,
    company_address : String,
    company_city : String,
    company_state : String,
    companyrep_name : String,
    companyrep_email : String,
    company_telnum : String,
    company_zip : String,
    company_website : String,
    timezone : String,
    company_logo : String,
    company_country : String,
    product_requested : String,
    methodof_payment : String,
    dateof_request : String,
    dateof_expiry : String,
});

var endUserRegisterSchema = new Schema({
    username : String,
    company_name : String,
    password : String,
    fullname : String,
    company_ccy: String,
    company_timezone : String    
})

module.exports = mongoose.model('Subscription',SubscriptionSchema);
module.exports = mongoose.model('Users',endUserRegisterSchema);

งั้นเพิ่มมันสำหรับเส้นทางมันควรจะมองแบบนี้

ที่ router ใน users.js ซึ่งมันควรจะต้องช่วยข้อมูลที่เป็นแบบนี้

router.post('/', function (req, res) {
  var newReg = new Users();

  newReg.username = req.body.username;
  newReg.company_name = req.body.company_name;
  newReg.password = req.body.password;
  newReg.fullname = req.body.fullname;

  newReg.save(function(err,Users){
    if(err){
      res.send('Error registering User');
    }else{
      res.send(Users);
    }
  });
});

งั้นบน app.js ผมแค่เพิ่มที่อยู่ URL ที่สัมพันธ์กัน

เพื่อเรียกดูที่เหลือรูปแบบ api. ทั้งหมดนี้ทำงานแต่ผมมีปัญหาเรื่องมันไม่ช่วย informtion มต้อง Mongo DB. ตอนที่ฉันขอผ่านเหมื LANGUAGE เหมือนนี้

{
  "username":"admin@********.com",
  "company_name":"blah blah blah",
  "password":"supermna1",
  "fullname":"Admin_blah blah"
}

ฉันกลับมาเข้าเรื่องเป็นการตอบสนมากกว่าที่เต็มไปด้วยข้อมูล

{
    "_id": "619ddde9ff437222b17e888d",
    "company_name": "blah blah blah",
    "__v": 0
}

มีบางอย่างที่ผมไม่ได้ใช่มั้ย? ฉันคงต้องการรูปแบบของช่วยทำให้ชัดเจนอยู่ที่นี่

mongodb node.js rest
2021-11-24 06:43:06
2
0

แยกกันไปเล็กกชิ้นทำงานสำหรับฉันและของทั้งหมดเป็นคนดีแล้ว อะไรก็ตามที่ชุดรูปแบบอันหนึ่งกำลังสร้าง,แบ่งแยกออกไป schemas. พวกผู้ชมน่ะได้ยินพวกเธอว่าฉันทำอะไรและทุกอย่างโอเคเรื่องนี้จบ

2021-11-24 07:19:57
0

พยายามทำแบบนี้แทน

router.post('/', async function(req, res) {

  try {
    var newReg = new Users();

    newReg.username = req.body.username;
    newReg.company_name = req.body.company_name;
    newReg.password = req.body.password;
    newReg.fullname = req.body.fullname;

    await newReg.save();
    res.send(newReg);
  } catch (err) {
    res.send('Error registering User');
  }
});

2021-11-24 08:18:37

ในภาษาอื่นๆ

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

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

ดังอยู่ในนี้หมวดหมู่

ดังคำถามอยู่ในนี้หมวดหมู่