Мангуст, выдвинь массив Model.update не является функцией

1

mongoose categorySchema:

    const CategoryAdvertSchema = new mongoose.Schema({
        UniqueHomes: {
            cave: { type: Boolean, default: false },
            natureLodge: { type: Boolean, default: false },
            castle: { type: Boolean, default: false },
            farmStay: { type: Boolean, default: false }
        },
        PropertyType: {
            apartment: { type: Boolean, default: false },
            villa: { type: Boolean, default: false },
            loft: { type: Boolean, default: false },
            yurt: { type: Boolean, default: false }
        },
        Others: [CategoryDynamiqueSchema]
    });

Мой mongoose OtherShema для массива push:

    const CategoryDynamiqueSchema = new mongoose.Schema({
        dayOfCategory: { type: Date, default: Date.now },
        nameOfCategory: { type: String },
        typeOfCategory: { type: String }
    });

Мой API:

category.post('/category', jwt.checkUserToken, (req, res) => {
    const dayOfCategory = Date.now();
    const nameOfCategory = req.body.nameOfCategory;
    const typeOfCategory = req.body.typeOfCategory;

    CategoryAdvert.update({
        $push: {
            Others: {
                dayOfCategory: dayOfCategory,
                nameOfCategory: nameOfCategory,
                typeOfCategory: typeOfCategory
            }
        }
    }, { new: true }, (err, category) => {
        if (err) {
            res.json({ success: false });
            console.log('err : ', err);
        } else {
            console.log("La catégorie '" + nameOfCategory + "' a bien été ajouté");
            res.json({ success: true });
        }
    });
});

Когда я пытаюсь нажать массив, я получаю следующую ошибку:

TypeError: CategoryAdvert.update не является функцией

Теги:
arrays
mongoose
push

1 ответ

0

я делаю легкие изменения, и он работает

    category.post('/category', jwt.checkUserToken, (req, res) => {
        console.log('req.body => ', req.body);
        const dayOfCategory = Date.now();
        const nameOfCategory = req.body.nameOfCategory;
        const typeOfCategory = req.body.typeOfCategory;

        Advert.update({
            $push: {
                'CategoryAdvert.Others': {
                    dayOfCategory: dayOfCategory,
                    nameOfCategory: nameOfCategory,
                    typeOfCategory: typeOfCategory
                }
            }
        }, { new: true }, (err, category) => {
            if (err) {
                res.json({ success: false });
                console.log('err : ', err);
            } else {
                console.log("La catégorie '" + nameOfCategory + "' a bien été ajouté");
                res.json({ success: true });
            }
        });
    });

Ещё вопросы

Сообщество Overcoder
Наверх
Меню