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

176
Views
convert $_id to string on the fly

I have the following update query, I want to use the value of the _id field. However, I can't, because _id is an ObjectId. and the field that I am writing on requires a string.

How to convert the _id to a string on the fly, within the request, in the concat function?

{ $concat: [`email`, ' #deleted(','$_id', ')'] }
  • I am using MongoDB in Mongoose In JavaScript.

full code if required:

await Model.findOneAndUpdate(req.params.id, [
    {
      $set: {
        email: {
          $concat: ['$email', ' #deleted(', '$_id', ')'],
        },
        _archived: Date.now(),
      },
    },
  ])

currently getting:

MongoServerError: Plan executor error during findAndModify :: caused by :: $concat only supports strings, not objectId

about 4 years ago · Juan Pablo Isaza
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!