Mongoose:如何在数组中填充

问题描述

我正在使用快速服务器返回数据库数据,我的架构目前设置如下:

NetworkRequest

我尝试像这样填充它以输入用户 ID 和用户名

const reviewSchema = new mongoose.Schema(
  {
    user: { type: mongoose.Schema.Types.ObjectId,ref: "User",required: true },comment: { type: String,rating: { type: Number,},{
    timestamps: true,}
)

const productSchema = new mongoose.Schema(
  {
    name: { type: String,required: true,unique: true },price: { type: Number,isVisible: { type: Boolean,default: false },description: { type: String },shortDescription: { type: String },image: { type: String },labels: { type: Array,default: [] },category: {
      type: mongoose.Schema.Types.ObjectId,ref: "Category",required: false,rating: { type: Number },numReviews: { type: Number,default: 0 },reviews: [reviewSchema],}

但我得到了错误

 const product = await Product.findById(req.params.id).populate(
      "review.user name id"
    )
    if (product) {
      res.send(product)

谢谢:)

解决方法

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

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

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