1

to be more specific. I have two collections first category collection:

    const mongoose = require('mongoose');
    const categorieSchema = new mongoose.Schema({
        CategoryDynamique: [{
            dayOfCategory: { type: Date, default: Date.now },
            nameOfCategory: { type: String },
            typeOfCategory: { type: String }
        }]
    });

    const Categorie = mongoose.model('Categorie', categorieSchema);

    module.exports = Categorie;

and advert collection

    const mongoose = require('mongoose');
    const CategoryAdvertSchema = require('./category_advert');
    const ReservationAdvertSchema = require('../reservation/reservation_advert');
    const CommentaryAdvertSchema = require('./commentary_advert');

    const advertSchema = new mongoose.Schema({
        idCreateurAdvert: {type String},
        titleAdvert: {type: String},
        descriptionAdvert: {type: String},
        shortdescriptionAdvert: {type: String},
        priceAdvert: {type: Number, min: 0},
        dateCreationAdvert: {type: Date, default: Date.now},
        infoDisponibilityAdvert: {type: Boolean, default: true},
        CategoryAdvert: [CategoryDynamiqueSchema],
        ...
    });

    const Advert = mongoose.model('Advert', advertSchema);

    module.exports = Advert;

I need to dynamically convert all objects in the array (category) into another array (advert), the category name would become the name of a boolean set to false by default. I know it's not very explicite so I will show you a concrete example of what I am trying to do :

for exemple with a object of my array (categorie collection) :

    _id:5af422045c57804e4060673c
        CategoryDynamique:Array
            0:Object
                _id:5af4283ff52b485584405ebe
                dayOfCategory:2018-05-10 13:08:47.289
                nameOfCategory:"Castel" /* the name (string) to convert to boolean */
                typeOfCategory:"Text"
            1:Object
            2:Object
        __v:0

to be convert in my advert array for

    _id:5af1c3208ef23e05bc202a43
    infoDisponibilityAdvert:true
    idCompany:"5af1b18fe4106c3498b99976"
    titleAdvert:"Title"
    shortdescriptionAdvert:"ghk"
    descriptionAdvert:"ghjk"
    InfoAdvert:Object
    Address:Object
    Contact:Object
    Vote:Object
    CategoryAdvert:Array
        0:Object
            Castel:false /* le name after to be convert */
    priceAdvert:500
    dateCreationAdvert:2018-05-08 17:32:48.775
    idCreateurAdvert:"5af1ae672756be34ec34345b"
    CommentaryAdvert:Array
    __v:0

I do not see how to proceed

Romain
  • 21
  • 3

0 Answers0