如何在node.js中为此代码编写模式
您可以这样做:如何在node.js中为此代码编写模式,node.js,mongoose,nested,Node.js,Mongoose,Nested,您可以这样做: _id :hhjjdfghjkkmdfghjkl8888 orderDetail: [ { fitoName:, fitoCode:, ProviderName: ProviderCode: Quantity: storUrl:fitotouch.com/fivestart/chinasore }, { fitoName:,
_id :hhjjdfghjkkmdfghjkl8888
orderDetail:
[
{
fitoName:,
fitoCode:,
ProviderName:
ProviderCode:
Quantity:
storUrl:fitotouch.com/fivestart/chinasore
},
{
fitoName:,
fitoCode:,
ProviderName:
ProviderCode:
Quantity:
storUrl:fitotouch.com/fivestart/chinasore
}
]
}
你可以用这种方法来做
const mongoose = require("mongoose");
const OrderDetails = mongoose.Schema(
{
fitoName: String,
fitoCode: String,
providerName: String,
providerCode: String,
quantity: Number,
storUrl: String
},
{ _id: false } // If you don't want an ID to be created by MongoDB
);
const Orders = mongoose.model(
"orders",
new mongoose.Schema(
{
orderDetail: {
type: [OrderDetails],
required: true
}
},
{ timestamps: true }
)
);
使用此参考url:
https://code.tutsplus.com/articles/an-introduction-to-mongoose-for-mongodb-and-nodejs--cms-29527
您应该更加精确。您的问题一点也不清楚,请对您的问题进行解释。@muhmad Zeshan如何将其保存在node.js中
var mongoose = require('mongoose');
mongoose.connect('mongodb://localhost/mongoose_basics');
var authorSchema = mongoose.Schema({
_id: mongoose.Schema.Types.ObjectId,
name: {
firstName: String,
lastName: String
},
biography: String,
twitter: String,
facebook: String,
linkedin: String,
profilePicture: Buffer,
created: {
type: Date,
default: Date.now
}
});
var Author = mongoose.model('Author', authorSchema);