5

I have a collection called products with the following items

[
  { 
    name: 'Product 1'
    images: ['http://staging.example.com/1', 'http://production.example.com/2'],
    ... 
  },
  { 
    name: 'Product 2'
    images: ['http://production.example.com/3'],
    ... 
  }
]

I want to find documents that contain string staging in the images array.

I tried couple of things like using $contains but mongo throws error saying I cannot use $contains with array.

Madhusudhan
  • 8,374
  • 12
  • 47
  • 68

2 Answers2

2

I think you might need regex searching here.

Try:

db.collection.find({images: /staging/});
Mạnh Quyết Nguyễn
  • 17,677
  • 1
  • 23
  • 51
0
db.products.find({images: /staging/i});

I think this will may help