title: MongoDB > Adding a new item into an object inside an array
body: <p>I have a collection that looks like this:</p>
  
  <pre><code>{
      _id: ...,
      checkins: [
          {
              id: ...,
              createdAt: 1488052032,
              ...
          },
          {
              id: ...,
              createdAt: 1488052032,
              ...
          }
      ]
  }
  </code></pre>
  
  <p>I want to add a new element called <code>created</code> next to the <em>id</em> and <em>createdAt</em> attributes (inside checkins, an array of objects). And I want to do it for all the elements that doesn't have this new element. </p>
  
  <p>I know how to check if an object has already an attribute in it, but I am having some problems adding the element. I am using the code below and returns me an error saying: <em>The positional operator did not find the match needed from the query</em>. </p>
  
  <pre><code>db.profiles.updateMany(
      {},
      {$set: {"checkins.$.created": new Date(0)}}
  )
  </code></pre>
  
  <p>Any ideas about what I am doing wrong? </p>