Getting error in using $or

MongoDB Enterprise Cluster0-shard-0:PRIMARY>
MongoDB Enterprise Cluster0-shard-0:PRIMARY> db.movies.aggregate(pipeline)
uncaught exception: Error: command failed: {
“operationTime” : Timestamp(1600717583, 1),
“ok” : 0,
“errmsg” : “unknown operator: $or”,
“code” : 2,
“codeName” : “BadValue”,
“$clusterTime” : {
“clusterTime” : Timestamp(1600717583, 1),
“signature” : {
“hash” : BinData(0,“evlwL5aTCaNu+mr2yivH8Addm3Q=”),
“keyId” : NumberLong(“6829321948548300802”)
}
}
} : aggregate failed :

You can use $in rather than $or.

And I do not think that the requirements are for rating.

And I do not think that the requirements are for genere.

Thanks for your response.
Why do you think that rating and genere are not required?
Also can you please try with $or?

I did not write that they are not required. I wrote that the requirements are not for rating and genere. They are for

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

ok.
Can you please have a look for this issue too.
My this pipeline is not returning any result.
var pipeline =

But if I remove language and ratings this is returing some result.

It really think it was clear.

You enter genere and the requirement is genres.

You enter language and the requirement is languages.

You enter rating and the requirement is rated.

2 Likes

Hi @Nikita_Kulshreshtha,

In addition to @steevej-1495’e reply, check for the following things:

Use of $in operator with languages field is not correct, try using another Array Query Operator

If you still get any error in your aggregation pipeline, let me know and I can initiate a discourse inbox thread where you can share the pipeline with us.

Thanks,
Sonali

yes please. I am not getting any data with this pipeline. Also not sure what is wrong in this.

Hi @Nikita_Kulshreshtha,

Please check your discourse inbox and feel free to reach out if you have any questions.

Kind Regards,
Sonali

I have also found that it matters where you put the $or. Different query operators work somewhat differently in terms of where you put them relative to fields.