How to query a embedded array of objects in mongodb if one of the field contains objectId?

  Kiến thức lập trình

I have a document which is like this

{
properties:[{_id:ObjectId("adsfasdf"),tId:ObjectId('fasdfasfd'),value:'maxium'}]
}

I want to find all the documents which have a specific tid and a value. And I have to do it like properties: {}. I can’t change the document structure and I have to have a key:value kind of query.
I tried this elemMatch but its not working if I remove the tId and try it works but if keep the tId then only it doesn’t work.

{ properties: {$elemMatch:{tId:ObjectId('6660052fc63fe43203b6ecec'), value: 'maximum' }} }  

{ customProperties: {$elemMatch:{propertyId:ObjectId(‘6660052fc63fe43203b6ecec’), value: ‘maximum’ }} }

Theme wordpress giá rẻ Theme wordpress giá rẻ Thiết kế website

LEAVE A COMMENT