Lab - $match: movies collection is not updated? 🤷

Hi folks! I have just started the Aggregation Framework Course.

I was able to connect to the cluster with the given connection string and find the aggregations database, however, I wasn’t able to find the fields “rated” and “languages” in the movies collection. Therefore, I’m not able to complete the Lab - $match.

Am I doing something wrong? here’s the screenshot of what I got:

1 Like

Hi @Wicleice_Fabio,

If we are talking about the mflix database, these fields aren’t present in 100% of the documents.

image

Use MongoDB Compass and run a Schema Analysis on it.

Cheers,
Maxime.

2 Likes

In addition to @MaBeuLux88 suggestion, you could use the mongo shell.

For example:

MongoDB Enterprise Cluster0-shard-0:PRIMARY> db.movies.find( { "rated" : { "$exists" : true } } ).itcount()
23713
MongoDB Enterprise Cluster0-shard-0:PRIMARY> db.movies.find( { "languages" : { "$exists" : true } } ).itcount()
43444

You can even look at some values with:

MongoDB Enterprise Cluster0-shard-0:PRIMARY> query = { "languages" : { "$exists" : true } }
{ "languages" : { "$exists" : true } }
MongoDB Enterprise Cluster0-shard-0:PRIMARY> project = { "languages" : 1 }
{ "languages" : 1 }
MongoDB Enterprise Cluster0-shard-0:PRIMARY> db.movies.
... find( query , project ).
... limit( 2 ).
... pretty() 
{
	"_id" : ObjectId("573a1390f29313caabcd42bf"),
	"languages" : [
		"English"
	]
}
{
	"_id" : ObjectId("573a1390f29313caabcd4292"),
	"languages" : [
		"English"
	]
}

I agree that using Compass is more user friendly, but knowing how to work in the shell is also useful.

3 Likes

@Wicleice_Fabio,
When I look at your screen shot, I noticed that you never use the command use aggregations…

If you are in the shell… You need to switch databases first… Therefore, I wonder if you are actually looking at the aggregations database or not. You should have had a message “using to aggregations” after the use command.

this is my logon screen

PS D:\65945\m121> 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
{"t":{"$date":"2021-05-21T06:44:27.388Z"},"s":"W",  "c":"CONTROL",  "id":23321,   "ctx":"main","msg":"Option: This name is deprecated. Please use the preferred name instead.","attr":{"deprecatedName":"ssl","preferredName":"tls"}}
MongoDB shell version v4.4.5
connecting to: 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?authSource=admin&compressors=disabled&gssapiServiceName=mongodb&replicaSet=Cluster0-shard-0
Implicit session: session { "id" : UUID("aa57bb44-13ca-4a8c-a36f-92915d54b722") }
MongoDB server version: 4.2.14
WARNING: shell and server versions do not match
MongoDB Enterprise Cluster0-shard-0:PRIMARY> 

switching to aggregations renders this output

PS D:\65945\m121> 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
{"t":{"$date":"2021-05-21T06:44:27.388Z"},"s":"W",  "c":"CONTROL",  "id":23321,   "ctx":"main","msg":"Option: This name is deprecated. Please use the preferred name instead.","attr":{"deprecatedName":"ssl","preferredName":"tls"}}
MongoDB shell version v4.4.5
connecting to: 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?authSource=admin&compressors=disabled&gssapiServiceName=mongodb&replicaSet=Cluster0-shard-0
Implicit session: session { "id" : UUID("aa57bb44-13ca-4a8c-a36f-92915d54b722") }
MongoDB server version: 4.2.14
WARNING: shell and server versions do not match
MongoDB Enterprise Cluster0-shard-0:PRIMARY> use aggregations
switched to db aggregations
MongoDB Enterprise Cluster0-shard-0:PRIMARY> 

now listing collections

PS D:\65945\m121> 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
{"t":{"$date":"2021-05-21T06:44:27.388Z"},"s":"W",  "c":"CONTROL",  "id":23321,   "ctx":"main","msg":"Option: This name is deprecated. Please use the preferred name instead.","attr":{"deprecatedName":"ssl","preferredName":"tls"}}
MongoDB shell version v4.4.5
connecting to: 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?authSource=admin&compressors=disabled&gssapiServiceName=mongodb&replicaSet=Cluster0-shard-0
Implicit session: session { "id" : UUID("aa57bb44-13ca-4a8c-a36f-92915d54b722") }
MongoDB server version: 4.2.14
WARNING: shell and server versions do not match
MongoDB Enterprise Cluster0-shard-0:PRIMARY> use aggregations
switched to db aggregations
MongoDB Enterprise Cluster0-shard-0:PRIMARY> show collections
air_airlines
air_alliances   
air_routes      
bronze_banking  
child_reference 
customers       
employees       
exoplanets      
gold_banking    
icecream_data   
movies
nycFacilities   
parent_reference
silver_banking  
solarSystem     
stocks
MongoDB Enterprise Cluster0-shard-0:PRIMARY>

Hope this helps

But if you look at the screenshot you will see that the first command he runs is

db

and the shell output

aggregations

This means that aggregations was the default database specified in the URI he used to start the mongo shell. So he did not have to execute use aggregations because he was already using it. See https://docs.mongodb.com/manual/mongo/ to see the many ways to specify a default database.

The second command he ran is show collections and the output matches yours. That further confirms he was using the appropriate database.

1 Like

Ok… Thanks, I couldn’t see his connection string in his screen shot. I only see what the shell is connecting to.

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