Tebe
Tebe

Reputation: 3214

Mongo querying if array contains value

I have such document tructure: enter image description here

I need to find all documents where 'full' key is equal to '20200518_cbmoAXY.jpeg'

The best query I ended up with is:

db.getCollection('Advert').find({ $where: "this.images && this.images.length && (this.images[0].full == '20200518_cbmoAXY.jpeg')" })

But it finds nothing although record is present.

Upvotes: 0

Views: 49

Answers (1)

Tebe
Tebe

Reputation: 3214

This is how I solved:

 db.getCollection('Advert').find({ 'images.0.full' : '20200518_cbmoAXY.jpeg'})

Upvotes: 1

Related Questions