Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

155
Views
Cannot update object value, keeps overwriting by strange id | javaScript Mongodb

I couldn't update object value and figure out how...

The thing I wan to do is if the frequency is one time, return query with 'creatorDetails.uuid' and measureId.

hasCompleted(userId) {
  // ...
  const query = {
    'creatorDetails.uuid': userId,
    measureId: this._id,
  };

  if (this.typeOptions.frequency === Frequency.ONE_TIME) {
    return query;
    console.log('query - inside', query);
  }
  // ...
  console.log('query - outside', query);
  return MeasureData.find(query).count() > 0;
}

But this didn't work well.

console.log('query - inside, query) shows

{
  creatorDetails.uuid: "wD7BaeY6SsNSBgjbg"
  measureId: "RMLY8unSwSJtRDde2"
}

console.log('query - outside, query) shows

{
  creatorDetails.uuid: "wD7BaeY6SsNSBgjbg"
  measureId: "PPt4tnGNxW34F5o8t" 
}

So I tried below.

hasCompleted(userId) {
  // ...
  const query = {
    'creatorDetails.uuid': userId,
    measureId: this._id,
  };

  if (this.typeOptions.frequency === Frequency.ONE_TIME) {
    // query.creatorDetails.uuid = userId; // this cause an error as well
    query.measureId = this._id; // added
    console.log('query - inside', query);
  }
  // ...
  console.log('query - outside', query);
  return MeasureData.find(query).count() > 0;
}

console.log('query - inside', query) shows the same

{
  creatorDetails.uuid: "wD7BaeY6SsNSBgjbg"
  measureId: "RMLY8unSwSJtRDde2"
}

console.log('query - outside', query) shows also the same

{
  creatorDetails.uuid: "wD7BaeY6SsNSBgjbg"
  measureId: "PPt4tnGNxW34F5o8t" 
}

Somehow measureId gets overwrote by a strange measureId PPt4tnGNxW34F5o8t

I also tried push inside of hasCompleted()

if (this.typeOptions.frequency === Frequency.ONE_TIME) {
  query.measureId.push(this._id)
} 

But I got an error saying query.measureId.push id not a function

Does anybody know how to update query? Thank you

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

I think there is a problem with the code:

You have to console first and then return otherwise it won't call the console.log because of unreachable statement

hasCompleted(userId) {
  // ...
  const query = {
    'creatorDetails.uuid': userId,
    measureId: this._id,
  };

  console.log(this.typeOptions.frequency, Frequency.ONE_TIME, this.typeOptions.frequency === Frequency.ONE_TIME);
  if (this.typeOptions.frequency === Frequency.ONE_TIME) {

    console.log('query - inside', query);
    return query; // you have return after doing the console
  }
  // ...
  console.log('query - outside', query);
  return MeasureData.find(query).count() > 0;
}

Can you try this and let me know if there is any change in output or not?

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!