【发布时间】:2019-12-05 16:45:46
【问题描述】:
我正在尝试在注册时发送用户对象。该用户对象具有许多属性,这些属性被发送到后端并正确添加到数据库中。但是,有一个属性,一个名为vouchers 的数组,当我添加它时,用户对象不会发送到数据库。
这是从离子前端发送到后端的用户对象的代码:
let userobj = {
username: this.username,
name: this.name,
region: this.region,
building: this.building,
password: this.password,
confirmPassword: this.confirmpassword,
points: 300,
vouchers: [{ companyId: "", companyname: "" }]
};
在后端,这是猫鼬模型:
const mongoose = require("mongoose");
var Voucher = mongoose.Schema.Types.Voucher;
const userSchema = mongoose.Schema({
username: {
type: String,
required: true,
trim: true,
lowercase: true
},
password: {
type: String,
required: true,
trim: true
},
name: {
type: String,
required: true,
trim: true
},
region: {
type: String,
required: true,
trim: true
},
building: {
type: Number,
required: true,
min: 0
},
points: {
type: Number,
required: false,
min: 0
},
vouchers: {
type: [Object],
status: [String],
required: false,
default: []
},
createdAt: {
type: Date,
default: Date.now
},
updatedAt: Date
});
mongoose.model("User", userSchema);
【问题讨论】:
标签: node.js angular mongodb ionic-framework