mongodb - Can't find documents by criteria containing string objectId value -
i have collection list such:
{username: 'somename', friendid: '57d725d6b8b144044602bf74' <-- reference objectid doc }
when query docs in collection criteria {friendid : '57d725d6b8b144044602bf74'} no results . other field query works fine.
i tried convert value objectid('57d725d6b8b144044602bf74')
though value string, still no go.
why failing search type of string ?
you trying achieve 'self-join' in mongodb , seems rely on _id field generated mongodb.
i suggest supply custom _id fields document.
eg:
{_id:"alex", name:"alex", friendid:""} {_id"john", name"john", friendid:"alex"}
and can execute queries ease on friendid field. give shot , see if make sense requirement.
Comments
Post a Comment