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

521
Views
find all entries having type_id:ObjectId('random id')

I am trying to repair a mongodb database where in some of the type_id ObjectId got inserted i tried to use regex but this is not working

find({"type_id":{$regex:/ObjectId\(.*\)/}})

Any Suggestion?

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Simple version:

db.foo.find({"type_id": {$type: "objectId"}});

Using the agg pipeline. I prefer pipelines because as your expression complexity grows, you don't get bound into the older, smaller feature set of find:

db.foo.aggregate([
    { $match: {$expr: {$eq: [{$type:"$type_id"}, "objectId"]} }}
]);

Look at https://docs.mongodb.com/manual/reference/operator/query/type to find the string values returned by $type.

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!