Skip to the content.

Week 5 – Homework

Load the sample data provided by MongoDB into your Atlas cluster.

Task 1

For task one, we are going to work with sample_weatherdata.data. You should select only documents that match the following criteria:

In order to perform this task, you need to create a variable as follows:

var match = {$match: {...}}

How many documents match these conditions?

Answer: 3

Task 2

Define a project stage in order to:

Create a new variable as follows:

var project = {$project: {...}}

Pass both the match stage defined in task one and the newly created project within your aggregation pipeline.

This is the expected output:

{
	"ts" : ISODate("1984-03-08T12:00:00Z"),
	"position" : {
		"coordinates" : [
			171.2,
			23.2
		]
	},
	"callLetters" : "SHIP",
	"pressure" : 9999.9,
	"change" : "4",
	"discrepancy" : "2"
}
{
	"ts" : ISODate("1984-03-12T18:00:00Z"),
	"position" : {
		"coordinates" : [
			4.5,
			49.5
		]
	},
	"callLetters" : "SHIP",
	"pressure" : 9999.9,
	"change" : "6",
	"discrepancy" : "2"
}
{
	"ts" : ISODate("1984-03-12T12:00:00Z"),
	"position" : {
		"coordinates" : [
			-9.1,
			43.6
		]
	},
	"callLetters" : "SHIP",
	"pressure" : 9999.9,
	"change" : "6",
	"discrepancy" : "2"
}

Task 3

Let’s turn to tate.artists. You are required to design an aggregation, doing the following:

This is the expected result:

{ "_id" : "Feminist Art", "count" : 18 }
{ "_id" : "Performance Art", "count" : 10 }
{ "_id" : "Young British Artists (YBA)", "count" : 9 }
{ "_id" : "Conceptual Art", "count" : 9 }
{ "_id" : "Abject art", "count" : 8 }