title: How to add attribute to all documents in a collection, with same data of another attribute in MongoDB?
body: <p>I've seen <a href="https://stackoverflow.com/questions/7714216/add-new-field-to-every-document-in-a-mongodb-collection">this question</a> and it could be useful, but I need some extra steps.</p>
  
  <p>I have a collection of <code>Sites</code> filled with <code>name</code>, <code>data</code> and a field called <code>infoBox</code> that is an object.</p>
  
  <pre><code>infoBox: {
      coordX: {
        type: Number,
      },
      coordY: {
        type: Number,
      },
      type: {
        type: Number,
        enum: [InfoBoxType.line, InfoBoxType.horizontal, InfoBoxType.vertical],
      },
      midPoint: {
        coordX: {
          type: Number,
        },
        coordY: {
          type: Number,
        },
      },
  </code></pre>
  
  <p>So, I need to add another attibute to all infoboxes of the sites called "<code>levels</code>" that is an <strong>array</strong>, and this field must contains two objects like <code>InfoBox</code>, with the same values, but with empty 'levels'. (both infobox 1 &amp; 2 with same values).This is to initialize the DB, later these values will be editted by the users.</p>
  
  <p>Trying to be clear, I actually have:</p>
  
  <pre><code>Site
      data
      name
      infobox
          coordx
          coordy
          midpoint
              coordx
              coordy
  </code></pre>
  
  <p>and I need</p>
  
  <pre><code>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)
  </code></pre>
  
  <p>How can I accomplish this?</p>
  
  <p>Extra info:
  Mongo version 4.2</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>I am trying to make it with something like this, but with no luck yet:</p>
  
  <pre><code>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 } });
  </code></pre>