Chapter 1. Lab:Match > Field "Languages" not exists in the all the movies collection..!

Hie,

This question is related to Lab - $match .

I did not find any field called languages in the collection movies. Because of that i’m not getting the output.

This is the cluster i have connected to…

mongo “mongodb://cluster0-shard-00-00-jxeqq.mongodb.net:27017,cluster0-shard-00-01-jxeqq.mongodb.net:27017,cluster0-shard-00-02-jxeqq.mongodb.net:27017/aggregations?replicaSet=Cluster0-shard-0” --authenticationDatabase admin --ssl -u m121 -p aggregations --norc

At what stage are you getting the error? The field may not exist in all documents, so your first stage should be some kind of stage to eliminate documents with no languages field or an empty languages field.

Hi,

As @steve16513 pointed out, there are documents without a language field.

Hint: You could use a query operator which filters the documents where all the specified values are in an array field.

José Carlos

@krishna_chowdary is right! The answer is being affected because the languages field is not on the movies collection. I am getting 877 instead of 23! Did you get to resolve this ?

Hi,

Just filter by {languages: {$all: ["English", "Japanese"]}} to retrieve the desired documents.

José Carlos

Thanks @jcarlosgarcia, it worked! :+1:

I am getting 20 documents

First, this thread is a few months old.

Second, you should not add a new question to an existing thread. Working on different issues on a single thread is complicated.

Finally, if you get 20 documents it is because only 20 documents have both English and Japanese as language.

Consult https://docs.mongodb.com/manual/reference/operator/query/all/ for more information on the $all operator.