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);

다음에 추가한 노선이 될 것으로 예상되는 이처럼 보

라우터 in 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

를 찾아보 REST api 를 사용합니다. 이 모든 작업,그러나 문제를,그것을 저장하지 않는 앵무새에 완전히 몽고 DB. 를 통과 할 때 JSON 으로 다음과 같이

{
  "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

분리로 작은 조금 나를 위해 일과 모든 좋은 이제. 어떤 스키마 중 하나입니다 만들기,분할로 별도의 스키마. 그게 내가 그리고 모든 것이 잘 이 끝입니다.

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ý
..................................................................................................................