title: Strange behavior on when I press button many times very quick in NODE.JS
body: <p>I have got 2 cards with 2 candidates, every candidate has a button where user can have a unique vote, the card have a box with <strong>total</strong> votes also, if the user make a vote for the first candidate, then the value of <strong>total</strong> in both cards is updated (in a card is substracted in another is added), . But when I press the button many times and very fast, the data returned by the backend is incorrect. Someone can explain what is happening please.</p>
  <hr />
  <p>TEMPLATE OF COMPONENT IN ANGULAR</p>
  <blockquote>
  </blockquote>
  <pre><code>&lt;mat-card class=&quot;example-card&quot; *ngFor=&quot;let candidate of candidates; let i = index&quot;&gt;
  
      &lt;mat-card-actions&gt;
          &lt;button mat-raised-button class=&quot;button-vote&quot; (click)=&quot;saveVote(candidate.userVotes[0], candidate)&quot;&gt;
              &lt;mat-icon color=&quot;accent&quot; aria-hidden=&quot;false&quot; aria-label=&quot;Example home icon&quot;&gt;pan_tool&lt;/mat-icon&gt;
          &lt;/button&gt;
          &lt;div class=&quot;result&quot; mat-fab&gt;{{candidate.totalVotes}} votos&lt;/div&gt;
      &lt;/mat-card-actions&gt;
  &lt;/mat-card&gt;
  </code></pre>
  <hr />
  <p>COMPONENENT.TS</p>
  <blockquote>
  </blockquote>
  <pre><code>export class CandidatesContainerComponent implements OnInit {
    candidates!: any[]
    constructor(
      private candidatesService: CandidatesService,
    ) { }
  
    ngOnInit(): void {
      this.obtainCandidates()
    }
    obtainCandidates() {
      this.candidatesService.getCandidates().subscribe((response: any) =&gt; {
        this.candidates = response
      })
    }
    saveVote(userVote: any, candidate: object | any) {
      this.candidatesService.updateVote(candidate._id, userVote.thisChoosed).subscribe(response =&gt; {
        if (response) {
          this.obtainCandidates()
        }
      })
    }
  
  
  }
  </code></pre>
  <hr />
  <p>CONTROLLER IN NODE.JS</p>
  <blockquote>
  </blockquote>
  <pre><code>const updateVote = async ( req = request, res = response ) =&gt; {
      const { candidateId, thisChoosed } = req.params
  
      const query = thisChoosed === 'true' ? candidateId: { $ne:candidateId }
  
      const previousVote = await Candidate.findOneAndUpdate(
          { _id:query },
          { 
              '$set': { 'userVotes.$[el].thisChoose': false }, 
              '$inc': { 'totalVotes':  -1 } 
          },
          { arrayFilters: [ 
              {&quot;el.user&quot;: req.user._id }]
          }
      )
  
      const newVote = await Candidate.findOneAndUpdate(
          { _id:candidateId },
          { 
              '$set': { 'userVotes.$[el].thisChoose': true }, 
              '$inc': { 'totalVotes': 1 } 
          },
          { 
              arrayFilters: [ {&quot;el.user&quot;: req.user._id }, ], new:true
          }
          
      )
      res.json( newVote )
  }
  </code></pre>
  <hr />
  <p>DATABASE</p>
  <pre><code>const VoteSchema = Schema({
      user:{
          type:Schema.ObjectId,
          ref:'User',
          required:[true, 'User is required - vote user']
      },
      thisChoosed:{
          type:Boolean,
          default:false
      },
      firstVote:{
          type:Boolean,
          default:true
      }
  })
  
  const CandidateSchema = Schema({
      names:{
          type:String,
          required:[true]
      },
      surnames:{
          type:String,
          required:[true]
      },
      userVotes:[VoteSchema],
      totalVotes:{
          type:Number,
          default:0
      },
  })
  </code></pre>