我想把陣列資料放在我的模式中,但它沒有顯示在我的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,
位置:字串。String。
startDate : Date。
endDate : Date, endDate : Date.
});
var Shop = mongoose.model('Shop', shopSchema) 。
因為我正在向shopType里面發送陣列格式的資料,但它沒有在schema里面顯示任何資料
。因為我正在從postman發送這個資料,我的格式看起來像這樣
{
"ownerId"/span> : "Own001"/span>,
"fname" : "Tom",
"lname" : "jerry",
"shopPlace" : {
"shopName" : "Juice Center",
"location" : "Mumbai",
},
"shopType" : ["Juice","蔬菜"]
}
但是當我發送這個資料時,只有ownerId、fname、lname、shopPlace顯示在模式里面,我的shopType資料不能被看到
const addTask = async (req, res)=> {
const { shopName, location } = req.body.shopPlace;
const shopDetails = new Shop({
商店名稱。
位置。
});
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,但它甚至沒有顯示在我的模式中
uj5u.com熱心網友回復:像這樣改變你的模式吧
var ownerSchema = Schema({
ownerId : String,
fname : String,
lname : String,
shopPlace : {
type: Schema.Types.ObjectId。
ref。'Shop'。
},
商店型別 : [{
type: String var Owner = mongoose.model('Owner'/span>, ownerSchema) 。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/319819.html
標籤:
上一篇:cURL顯示幾天以來的空白頁面
