Jam1
Jam1

Reputation: 649

Starts with and include regex in Mongodb

In my attributes key I want to find in the array records that are Special and has latenight : True.

"attributes" : [ "Alcohol: none", "BikeParking: True", "Special: {'dessert': False, 'latenight': False, 'lunch': False, 'dinner': False, 'breakfast': False, 'brunch': False}" ]

So far this is what I have db.restaurant.find({ attributes: {$in :[/^Special/]} });. But I do not know where to go from there. I want the regex to contain latenight : True as well.

Upvotes: 1

Views: 808

Answers (1)

Wiktor Stribiżew
Wiktor Stribiżew

Reputation: 626699

A regex that you are looking for is

/^Special.*'latenight': True/

See the regex demo.

Details

  • ^ - start of string
  • Special - a literal string
  • .* - any 0+ chars other than line break chars, as many as possible
  • 'latenight': True - a literal substring.

Note that you may replace the literal space with \s+ to match any 1+ whitespace chars.

Upvotes: 1

Related Questions