Mongodb Mongoose对象数组赢得';我不在邮递员那里工作

Mongodb Mongoose对象数组赢得';我不在邮递员那里工作,mongodb,mongoose,postman,Mongodb,Mongoose,Postman,在完成了关于MEAN Stack的课程后,我正在制作我自己的Web应用程序——食谱页面。我已经设计了我的模型,但是当我试图用新的配方填充数据库时,它就是不起作用。主要的问题是我想要储存配料的方式,它们将被储存在一张桌子上,然后每个食谱都有它的配料清单和每种配料的用量。例如,要做一些你需要的吐司,说“50克黄油和4片面包”。这是我正在使用的模式: var RecipeSchema = Schema({ name: String, desc: String, author:

在完成了关于MEAN Stack的课程后,我正在制作我自己的Web应用程序——食谱页面。我已经设计了我的模型,但是当我试图用新的配方填充数据库时,它就是不起作用。主要的问题是我想要储存配料的方式,它们将被储存在一张桌子上,然后每个食谱都有它的配料清单和每种配料的用量。例如,要做一些你需要的吐司,说“50克黄油和4片面包”。这是我正在使用的模式:

var RecipeSchema = Schema({
    name: String,
    desc: String,
    author: { type: Schema.ObjectId, ref: 'User' },
    category: { type: Schema.ObjectId, ref: 'Category' },
    ingredients: [{ amount: String, ingredient: { type: Schema.ObjectId, ref: 'Ingredient' }}],
    steps: [String],
    image: String,
    thumbnail: String,
    portions: Number,
    difficulty: Number,
    cookingTime: Number,
    comment: String
});
当我加入邮递员并尝试填写“吐司食谱”条目时,我有以下几点:

name:Toast
desc:Toast is a common breakfast staple.
author:5cad791a7b2e651f7803f5de
category:5cb1ff8f484a172984178a97
ingredients:[{"amount": "4 slices", "ingredient": "5cb1ffdb484a172984178a98"}, {"amount": "35 grs.", "ingredient": "5cb2000d484a172984178a99"}]
steps:['Toast the bread in the oven.','Spread some butter on each toast.']
image:'null'
thumbnail:'null'
portions:1
difficulty:1
cookingTime:15
comment:'null'
但我一直收到一个“cast Array”错误。可能是什么问题?这是我的模型、邮递员的问题还是我发送阵列的方式的问题

编辑:


显然,我在邮递员中发布阵列的方式存在问题。经过更多的测试,我上传了一份JSON格式的完整配方。结构是正确的(但是Juan建议的也可以使用,以使代码更干净)。

我不完全确定,但是当我使用mongoose时,内部对象内部有一个新的Schema对象,在这种情况下,它会在组件上

const IngredientSchema = new Schema({ 
    amount: String, 
    ingredient: { type: Schema.ObjectId, ref:'Ingredient' }
});

const RecipeSchema = new Schema({
    name: String,
    desc: String,
    author: { type: Schema.ObjectId, ref: 'User' },
    category: { type: Schema.ObjectId, ref: 'Category' },
    ingredients: [ IngredientSchema ],
    steps: [String],
    image: String,
    thumbnail: String,
    portions: Number,
    difficulty: Number,
    cookingTime: Number,
    comment: String
});