我试图将数组数据放入我的模式中,但它没有显示在我的mongodb模式
ownerSchema.js
var ownerSchema = Schema({
ownerId : String,
fname : String,
lname : String,
shopPlace : {
type: Schema.Types.ObjectId,
ref: 'Shop'
},
shopType String
});
var Owner = mongoose.model('Owner', ownerSchema);
shopSchema.js
var shopSchema = Schema({
_id : String,
shopName : String,
location : String,
startDate : Date,
endDate : Date
});
var Shop = mongoose.model('Shop', shopSchema);
,因为我在shopType中发送数组格式数据但它没有在schema中显示任何数据
当我从邮差发送这个时,我的格式是这样的
{
"ownerId" : "Own001",
"fname" : "Tom",
"lname" : "jerry",
"shopPlace" : {
"shopName" : "Juice Center",
"location" : "Mumbai",
},
"shopType" : ["Juice","vegetables"]
}
但是当我发送这些数据时,只有ownerId, fname,lname, shopPlace显示在模式中,我的shopType数据不能看到
const addTask = async (req, res) => {
const { shopName, location } = req.body.shopPlace;
const shopDetails = new Shop({
shopName,
location,
});
await shopDetails.save();
const { ownerId, fname, lname, shopType } = req.body;
const ownerDetail = new Owner({
ownerId,
fname,
lname,
shopType,
shopPlace: shopDetail._id,
});
await shopDetail.save();
};
我想将shopType存储为数组格式,但它甚至没有显示在我的模式中
像这样改变你的模式
var ownerSchema = Schema({
ownerId : String,
fname : String,
lname : String,
shopPlace : {
type: Schema.Types.ObjectId,
ref: 'Shop'
},
shopType : [{
type: String
}]
});
var Owner = mongoose.model('Owner', ownerSchema);