我正在尝试在注册时发送用户对象。这个用户对象有许多属性,这些属性被发送到后端并正确地添加到数据库中。但是,有一个属性,一个名为vouchers的数组,当我添加它时,user对象不会发送到数据库。
以下是从离子前端发送到后端的用户对象的代码:
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: "" }]
};在后端,这是mongoose模型:
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);发布于 2019-07-28 03:58:08
定义vouchers有一个对象数组
vouchers: [{
type: [Object], // There is no Schema Type in moongoose, change to [String]
status: [String]
}]不要担心你的vouchers: [{ companyId: "", companyname: "" }]
您想要使用companyId和companyname
更改架构..
vouchers: [{ companyId: String, companyname: String }]
https://stackoverflow.com/questions/57235282
复制相似问题