How to make this work

Hello,

Im struggeling for 3 - 4 days how I can tell this in a aggregate or a find

  • genres does not contain “Crime” or “Horror”
  • rated is either “PG” or “G”

It seems I cannot use two times a $or because the second time overwrites the first one.
But how can I make this work ?

https://docs.mongodb.com/manual/reference/operator/query/nin/

and

https://docs.mongodb.com/manual/reference/operator/query/in/

1 Like

that does not work both a a string so I thought of using $ ne

But still how can I make a query where I have to use two times a $or

A JSON document cannot have the same key twice.

An array can be used to $and or $or multiple clauses.

I do not understand the following:

But

{ rated : { $in : [ "P", "PG" ] } }

works fine even if rated is a string.

And since this thread is related to M121 at MongoDB University, it is best to have this thread over there in the course specific forum.

1 Like

If you are still stuck and you want an aggregation solution look at that also : )