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

391
Views
What benefit of using mongoose.Types.ObjectId instead of req.params.id to compare with the _id in Mongoose

For example

await Smartphones.findOne({_id: req.params.id})
await Smartphones.findOne({_id: ObjectId(req.params.id)})

To me it seem both return object, but I don't if it have any benefit of using ObjectId when comparing

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

If you are using ObjectId(req.params.id) it will try to parse the "req.params.id" value to mongoDB Object Id, if its unable to parse it throws an error as "req.params.id" is not a valid mongo object id

over 4 years ago · Santiago Trujillo Report

0

If you are using MongoDB Compass to fetch some data, you can't use the _id as a simple string, there you should use ObjectId for getting the data. An _id in the document can be of any form except an array, and the default format is ObjectId. The ObjectId is not just a simple format in MongoDB, other than that of a format it has some use-cases too, you can refer to this link

over 4 years ago · Santiago Trujillo 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!