Javascript 为什么我不能填充厨师';谁的文件?

Javascript 为什么我不能填充厨师';谁的文件?,javascript,node.js,mongodb,mongoose,mongoose-populate,Javascript,Node.js,Mongodb,Mongoose,Mongoose Populate,我有3个系列:食谱、厨师和食物类别。 我试图填充厨师收藏,但我不能;有什么问题 const recipeSchema = new mongoose.Schema({ chef: { type: mongoose.Schema.Types.ObjectId, ref: 'Chef', required: true }, foodCategory: { type: mongoose.Schema.Types.Ob

我有3个系列:食谱、厨师和食物类别。 我试图填充厨师收藏,但我不能;有什么问题

const recipeSchema = new mongoose.Schema({
    chef: {
        type: mongoose.Schema.Types.ObjectId,
        ref: 'Chef',
        required: true
    },
    foodCategory: {
        type: mongoose.Schema.Types.ObjectId,
        ref: 'FoodCategory',
        required: true
    },
})

const recipes = await Recipe.find({ chef: '608ed57e58e54d4b9486dae4' })
            .select("-__v")
            .sort({ name: 1 })
            .populate("Chef", 'name status filePath');

您正在尝试填充
Chef
而不是
Chef
,修复输入错误。它不起作用,我的朋友。您可以尝试
const recipes=wait Recipe.find({Chef:'608ed57e58e54db9486dae4')。选择(“-v”)。排序({name:1})。填充({path:'Chef})
console.log(食谱)
OMG,你是我的救星!问题出在哪里?是你的输入错误
.populate(“Chef”)
而不是
Chef
我只是修复了它,语法的改变是因为我的linter。通过如下方式指定您的选择
.populate({path:“chef”,select:'name status filePath'})