• Home
  • Jobs
  • Courses
  • Teachers
  • For business
  • Blog
  • ES/EN

0

16
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?

7 days 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.

7 days ago · Santiago Trujillo Report
Answer question
Remote jobs
Loading

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post job Plans Our process Startups
Legal
Terms and conditions Privacy policy
© 2022 PeakU Inc. All Rights Reserved.