Как найти в mongoose все совпадения по полю в ref?

Есть таблица variables

const {Schema, model, Types} = require('mongoose')

const schema = new Schema({
        name: {type: String, required: true, unique: true},
        value: {type: String, required: true},
        group: {type: Types.ObjectId, ref: 'Variables_group'},
        comment: {type: String},
        status: {type: Number, required: true, default: 0}
    },
    {
        timestamps: true
    })

module.exports = model('Variable', schema)

И есть таблица variables_groups

const {Schema, model} = require('mongoose')

const schema = new Schema({
        name: {type: String, required: true},
        value: {type: String, required: true},
        comment: {type: String},
        status: {type: Number, required: true, default: 0}
    },
    {
        timestamps: true
    })

module.exports = model('Variables_group', schema)

Хочу сделать поиск по таблице variables по полю group, но не по ID, а по variables_groups.name. Сначала пробовал таким образом

            const options = {
                'group.name': 'messages'
            }

            response.data = await Variable.find(options)

Ошибки не выдаёт, но и результата тоже никакого нет. Тогда я наткнулся на .populate, но так и не понял каким образом его надо правильно применить в моём случае, если он сюда вообще подходит


Ответы (0 шт):