I've seen this question and it could be useful, but I need some extra steps.
I have a collection of Sites filled with name, data and a field called infoBox that is an object.
infoBox: {
coordX: {
type: Number,
},
coordY: {
type: Number,
},
type: {
type: Number,
enum: [InfoBoxType.line, InfoBoxType.horizontal, InfoBoxType.vertical],
},
midPoint: {
coordX: {
type: Number,
},
coordY: {
type: Number,
},
},
So, I need to add another attibute to all infoboxes of the sites called "levels" that is an array, and this field must contains two objects like InfoBox, with the same values, but with empty 'levels'. (both infobox 1 & 2 with same values).This is to initialize the DB, later these values will be editted by the users.
Trying to be clear, I actually have:
Site
data
name
infobox
coordx
coordy
midpoint
coordx
coordy
and I need
Site
data
name
infobox
coordx
coordy
midpoint
coordx
coordy
levels
infobox1
coordx
coordy
midpoint
coordx
coordy
levels(empty)
infobox2
coordx
coordy
midpoint
coordx
coordy
levels(empty)
How can I accomplish this?
Extra info: Mongo version 4.2
EDIT
I am trying to make it with something like this, but with no luck yet:
let sites = await this.siteModel.find({});
const firstZoom = site.infoBox;
const secondZoom = site.infoBox;
const levelss = [
firstZoom,
secondZoom,
];
await this.siteModel.update({ _id: site._id }, { $set: { 'infoBox.levels.$': levelss } });