如何选择要使用Autopopulate Mongoose Mongodb检索的字段?

如何选择要使用Autopopulate Mongoose Mongodb检索的字段?,mongodb,mongoose,Mongodb,Mongoose,我正在使用插件mongoose autopopulate,但我不知道如何指定要从填充的集合中检索的字段 这是我的模式 const categoriaSchema = new Schema({ data: { type: String }, label: { type: String }, children: [{ type: mongoose.Schema.Types.ObjectId, ref: 'categorias',

我正在使用插件mongoose autopopulate,但我不知道如何指定要从填充的集合中检索的字段

这是我的模式

const categoriaSchema = new Schema({
    data: { type: String },
    label: { type: String },
    children: [{
        type: mongoose.Schema.Types.ObjectId,
        ref: 'categorias',
        autopopulate: true
    }],
    father: {
        type: mongoose.Schema.Types.ObjectId,
        ref: 'categorias',
        autopopulate: true
    },
    eventos: { type: Boolean },
    tienda: { type: Boolean },
    productos: [{
        type: mongoose.Schema.Types.ObjectId,
        ref: 'productos',
        autopopulate: true
    }]
})
所以我想选择children填充集合中的字段,因为productos字段带来了大量文档

我怎么能有这样的输出

{
    data: "Electronic",
    label: "Electronic",
    children: [
        { 
        data: "Mobiles",
        label: "Mobiles",
        children: [
            {   
            data: "Samsung",
            label: "Samsung",
            children: [],
            eventos: true;
            tienda: true;
            }
        ],
        eventos: true;
        tienda: true;
        }
    ],
    eventos: true;
    tienda: true;
}
我找到了解决办法

  children: [{
        type: mongoose.Schema.Types.ObjectId,
        ref: 'categorias',
        autopopulate: { select: '-productos' },

    }],
autopopulate接受选项,然后您可以选择或取消选择要排除或添加的字段