3

I'm using mongodb v4.0.3, and this happens both with the shell and in compass.

This only happens with a certain collection. It previously had overriden ids (instead of the default mongodb id, there was a string. I dropped the collection and I recreated it without that).

I have the following structure ("mystructure"), for example:

{  
   "_id":ObjectId("5bd44eb528d61e3374b5e6ea"),
   "custom_field":"data",
}

When I query it without a filter it returns all the docs:

db.mystructure.find({});

When I search for its objectid, it returns properly

db.mystructure.find( {"_id": ObjectId("5bd44eb528d61e3374b5e6ea")} );

But when I try to filter with any field, it doesn't return anything

db.mystructure.find( {"custom_field": "data"} );

At first I thought it would be solved recreating the collection with the automatically generated ids from mongodb but the problem persists. There are no "hidden" spaces in the string or anything like that. The same query in compass isn't working either. Other collections do work. It's on the same db, with the same user.

Why can this be?

Thank you very much.

dippas
  • 58,591
  • 15
  • 114
  • 126
user3743211
  • 51
  • 1
  • 3

1 Answers1

-1

you should write below code where 62c01e5a763d106152a2e53f is your _id

{_id:ObjectId('62c01e5a763d106152a2e53f')}

enter image description here

Suraj Rao
  • 29,388
  • 11
  • 94
  • 103
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jul 03 '22 at 18:34