更具体。我有两个集合第一类集合:
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;
和广告收藏
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;
我需要动态地将数组(类别)中的所有对象转换为另一个数组(广告),类别名称将成为默认设置为false的布尔名称。我知道它不是非常明确,所以我将向您展示我想要做的具体示例:
例如我的数组对象(类别集合):
_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
在我的广告数组中转换为
_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
我看不到如何继续