Mongoose two level population using KeystoneJs [duplicate]

旧街凉风 提交于 2019-12-06 06:01:05

In mongoose you can do this way:

regionModel.find().populate("countries").exec(function(err, regions){

    if(err){
        throw err;
    }

    // Regions with populate countries
    cityModel.populate(regions, {
        path: 'countries.cities',
        select: '_id name'
    },function(err, regions) {

        //Regions with Countries and Populated Cities

    });

})

Actually i dont familiar with keystone syntax, but i try to convert it to keystone syntax. Hope it works, if not please try to convert above code equivalent to keystonejs

keystone.list('Region').model.find()
        .populate('countries')
        .exec(function(err, regions){

            if(err){
                throw err;
            }

            keystone.list('City').model.find()
                    .populate('cities')
                    .exec(function(err, regions){
                        console.log(regions)
                    });

        });
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!