title: MongoDB concurrency when wirting to same array
body: <p>I have been reading about mongodb concurrency but to be honest I still don't get how things work in mongodb. In my use case for example I have a document holding the array of the user followers</p>
  <pre><code>const userFollowing = new mongoose.Schema(
      {
          userID : {
              type: mongoose.Schema.Types.ObjectId,
              required: true,
              ref: 'User'
          },
          followingProfiles: [{
              type: mongoose.Schema.Types.ObjectId,
              default: [],
              ref: 'Profile'
          }]
      }
  )
  </code></pre>
  <p>So let's assume the following happens two different users decide to follow the same user so I'm confused what would happen based on my code but here is what I do:</p>
  <p>1-I read the following document of the user</p>
  <p>2-I push the new reference in the array</p>
  <p>3- Save the document again.</p>
  <pre><code>//Get the user following list by Id
          const userFollowings = await UserFollowing.findOne({
              userID: req.user._id
          })
  
  
          const userProfile = await Profile.findOne({
              user: req.user._id
          })
  
       
          userFollowings.followingProfiles.push(profileID)
          await userFollowings.save()
  </code></pre>
  <p><strong>My Question</strong>: If the two users read the same instance of the document which let's say had 3 following and each one would add a new reference to the following array. The expected output is that the array after the concurrent writes would contain 5 indexes but I' scared that .save() overwites the entire document which would then make the later write only exist.</p>