我正在尝试为一系列对象制作模式,并且不确定如何做新的后端



我正在尝试为一个对象数组创建一个架构

我只是想确保到目前为止我在做什么是正确的。

const CartSchema = mongoose.Schema({
    cart: [{
        colorC: String,
        sizeC: String,
        date: Date,
        title: String,
        transactionID: Number,
        count: Number,
        lang: []
    }]
});

这就是我安装时数组的外观。

[{…}]
0:
category: "Mens Fashion"
colorC: null
count: 1
date: "Mon Jul 29 2019 02:08:07 GMT-0400 (Eastern Daylight Time)"
fabric: "100% Cotton"
id: 1
img: "img/product-1.png"
img2: "img/product-1-1.png"
img3: "img/product-1-2.png"
img4: "img/product-1-3.png"
inCart: true
info: " COMME DES GARCONS PLAY BASIC LOGO TEE"
lang: (3) ["en-US", "en", "pt"]
luxury: "All Luxury items are inspected to verify authenticity"
price: 200
size1: "Small"
size2: "Medium"
size3: "Large"
size4: "Extra Large"
sizeC: "Small"
title: "COMME DES GARCONS TEE"
total: 200
transactionID: 1564380487732
__proto__: Object
length: 1
__proto__: Array(0)

如果您想做一系列购物车,并且购物车有许多产品,则可以做这样的事情:

产品模式:

const ProductSchema = mongoose.Schema({
        colorC: String,
        sizeC: String,
        date: Date,
        title: String,
        transactionID: Number,
        count: Number,
        lang: []
});

,然后是一系列产品的集合

const CartSchema = mongoose.Schema({
        products: [ProductSchema]
});
const Cart = mongoose.model('Cart', CartSchema);

最新更新