无法在mongodb集合的文档中创建空对象值

时间:2020-03-27 10:15:14

标签: mongodb mongoose

我的代码如下:

   const meal = await Meal.create({
      mealCategory:req.body.mealCategory,
      mealCuisine:req.body.mealCuisine,
      imageURL: req.body.imageURL,
      isDeleted:req.body.isDeleted,
      editedAt:req.body.editedAt,
      createdAt:req.body.createdAt,
      restaurantID:req.body.restaurantID,
      ingredients:req.body.ingredients,
      mealSize:req.body.mealSize,
      mealPrice:req.body.mealPrice,
      mealQuantity:req.body.mealQuantity,
      mealName:req.body.mealName,
      nutrient:{}});
营养素是空物体。 Meal.create无法创建营养对象,因为该对象为空。 营养物质场在输入中消失。 我的用餐模式如下:

const mealSchema = mongoose.Schema({
  mealName: String,
  mealCategory: Object,
  mealCuisine: Object,
  mealSize: String,
  mealPrice: Number,
  mealQuantity: String,
  isDeleted: Boolean,
  createdAt: Date,
  editedAt: Date,
  imageURL: String,
  ingredients: Array,
  restaurantID: Object,
  price: Number,
  nutrient: Object,
  score: Array,
  flag: String,
  nutrient:Object,
  mealScore: Number,

});

营养素由于是空的而消失了。但是我想要在我的文档中。

0 个答案:

没有答案