Как передать данные во вложенный объект модели express.js

Есть модель

const postSchema = mongoose.Schema({
    owner: {
        type: mongoose.Schema.Types.ObjectId,
        ref: 'admin'
    },
    category: 
        {
            category_id: {
                type: String,
                required: true
            },
            name:{
                type:String
            },
            slug:{
                type:String
            }
        }
    ,

Я получаю в параметре id, его нужно передать в category - category_id

const getByCategoriesId = (req,res, next) => {
    Post.find({
        category:{
        category_id:req.params.categoryId
        }
    })
    .then((posts) => res.send(posts))
    .catch(next)
}

Как это правильно сделать ?


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