【问题标题】:Prisma MongoDB Array of ObjectsPrisma MongoDB 对象数组
【发布时间】:2023-02-14 07:53:00
【问题描述】:

我正在尝试将数据插入到具有 Prisma 模型对象值的 MongoDB 数组中。 我要插入的数据是带有图像、名称和描述的产品。

我试过这种方法,但出现错误。 我认为我的模型不正确

 const addProd = await prisma.products.create({
        data: {
            csso: [
                {
                    image: req.file.filename,
                    name: req.body.name,
                    desc: req.body.desc
                }
            ]
        }
    })

这是我的模特

model Products {
  id    String @id @default(auto()) @map("_id") @db.ObjectId
  csso String[]
}

【问题讨论】:

    标签: arrays mongodb object prisma


    【解决方案1】:

    Prima 建议映射所有要使用的实体。

    尝试这样做:

    model Products {
      id    String @id @default(auto()) @map("_id") @db.ObjectId
      csso  Csso[]
    }
    
    type Csso {
      image String
      name  String
      desc  String
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-02-10
      • 2015-02-25
      • 2021-09-24
      • 2021-06-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多