【发布时间】:2022-01-02 13:59:51
【问题描述】:
我在 MongoDB 中创建了第一个 Schema 和另一个(2 个表)来容纳 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);
然后将它添加到它应该看起来像这样的路线
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。所有这些工作,但我有一个问题,它没有将信息完全保存到 Mongo DB。 当我像这样传递 JSON 时
{
"username":"admin@********.com",
"company_name":"blah blah blah",
"password":"supermna1",
"fullname":"Admin_blah blah"
}
我将其作为 Response 取回,而不是完整数据
{
"_id": "619ddde9ff437222b17e888d",
"company_name": "blah blah blah",
"__v": 0
}
有什么我做错了吗?我在这里需要某种形式的澄清
【问题讨论】: