Regular expression not working MongoDB aggregation builder

I am trying to verify the answer for Lab - $group and Accumulators in MongoDB aggregation builder( in MongoDB Atlas). The answer is like this:

db.movies.aggregate([
  {
    $match: {
      awards: /Won \d{1,2} Oscars?/
    }
  },
  {
    $group: {
      ...
    }
  }
])

I am just pasting the same regular expression in the aggregation builder in a match stage. But then output is 0 documents. And I prefer using the aggregation builder to avoid confusion regarding brackets. Please guide me on how to properly use regular expression in MongoDB aggregation builder. Thanks :slight_smile:

Can you share the database/collection you are using? Is it sample_mflix.movies?

The aggregation builder samples the docs in the collection. It’s possible the sample has no documents that match that filter.

Yes right, it is sample_mflix.movies .
I didn’t quite get your answer, could you please elaborate it.

Your post is in M121 course.

There is no collection named sample_mflix.movies on the server you are supposed to use for this course.

For M121, the collection to use is aggregations.movies and your $match should work as it is.

For sample_mflix.movies from the Atlas sample data set, the field awards is an object and the the regular expression has to performed on the sub-field text.

1 Like

Sorry, my bad. I missed it somehow !

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.