title: Add timestamp to a new subdocument or subschema in mongoose
body: <p>I have this document in mongo atlas</p>
  <pre><code>_id: 5f8939cbedf74e363c37dd86,
  firstname: &quot;Person&quot;,
  lastname: &quot;Person lastname&quot;,
  sex: &quot;Masculino&quot;,
  age: &quot;20&quot;,
  birthDay: 2020-10-07T00:00:00.000+00:00,
  vaccines: Array
   0:Object
    dose: Array
     _id: 5f8939cbedf74e363c37dd87
     vaccine:5f7023ad96f7ed21e85be521
     createdAt:2020-10-16T06:12:27.726+00:00
     updatedAt:2020-10-16T06:12:27.726+00:00
   1:Object
    dose:Array
    _id:5f893a9ca98e97188c93fea8
    vaccine:5f70259796f7ed21e85be523
   2:Object
    dose:Array
    _id:5f893acda98e97188c93fea9
    vaccine:5f7023ad96f7ed21e85be521
  
  </code></pre>
  <p>This is my mongoose schema</p>
  <pre><code>const mySchema = new Schema({
    firstname: {
      type: String,
      required: true,
    },
    lastname: {
      type: String,
      required: true,
    },
    sex: {
      type: String,
      required: true,
    },
    age: {
      type: String,
      required: true,
    },
    birthDay: {
      type: Date,
      required: true,
    },
    vaccines: [
      {
        type: new Schema(
          {
            vaccine: {
              type: Schema.ObjectId,
              ref: &quot;Vaccine&quot;,
            },
            dose: Array,
          },
          { timestamps: true }
        ),
      },
    ],
  });
  
  </code></pre>
  <p>every time I add a new person the vaccines array gets one new object with the timestamp as you can see, in my js file I use this code:</p>
  <pre><code>const addPerson = (person) =&gt; {
    const myPerson= new Model(person);
    return myPerson.save();
  };
  </code></pre>
  <p>Then when I add a new vaccine for the same person this does not get the timestamp, I'm using this code for that:</p>
  <pre><code>const addPersonVaccine = async ({ params, body }) =&gt; {
    if (!params) return Promise.reject(&quot;Invalid ID&quot;);
    const vaccines = [body];
    const foundPerson = await Model.updateOne(
      {
        _id: params,
      },
      {
        $push: {
          vaccines: vaccines,
        },
      }
    );
    return foundPerson;
  };
  </code></pre>
  <p>This is what my body inside vaccines array has:
  <code>[ { vaccine: '5f72c909594ee82d107bf870', dose: 'Primera' } ]</code></p>
  <p>The problem is that I have no results about the next timestamps, as you can see in my mongo atlas document:</p>
  <pre><code>1:Object
    dose:Array
    _id:5f893a9ca98e97188c93fea8
    vaccine:5f70259796f7ed21e85be523
   2:Object
    dose:Array
    _id:5f893acda98e97188c93fea9
    vaccine:5f7023ad96f7ed21e85be521
  </code></pre>
  <p>Is that the best way to implement timestamps in subdocuments or sub schemas?</p>
  <p>I will appreciate your answers, thnks </p>