如何在猫鼬中建立一对多关系

问题描述

我正在学习mongoDB和mongoose,我正在尝试在客户和订单之间建立一对多关系 但出现一个无法创建之前访问orderSchema的错误。请帮助我解决错误。这是我的代码

    const customerSchema = new mongoose.Schema({
  _id: {
    type: Number,required: true
  },name: {
    type: String,maxlength: 50,},email: {
    type: String,orders: orderSchema,});

const productSchema = new mongoose.Schema({
  _id: {
    type: Number,required: true,price: {
    type: Number,}
});

const orderSchema = new mongoose.Schema({
  order_id: {
    type: Number,product: productSchema,customer: customerSchema
});

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)