Back to Samples

Database sample

Convert RDBMS schema into MongoDB collection.
RDBMS database has 2 tables: students and grades linked with a student_id key.
Write a query that lists Last name, First name and the Average of the Percent field.

MongoDB document structure:

{
	"_id" : ObjectId("56e45373a2acbb1f793805e6"),
	"first_name" : "Pirkko",
	"last_name" : "Koskitalo",
	"grades" : [
		{
			"grade" : 9,
			"percent" : 70
		},
		{
			"grade" : 10,
			"percent" : 80
		},
		{
			"grade" : 11,
			"percent" : 90
		},
		{
			"grade" : 12,
			"percent" : 100
		}
	]
}

Last name First name Average
{{ x.last }} {{ x.first }} {{ x.average + '%'}}