Lab - Changing Document Shape with $project

Hi All,

While executing:
validateLab2(pipeline)

I am getting the below error.

aggregations.movies.aggregate(…).toArray is not a function

Can someone please help?

Result of my pipeline is:

> {

“cursor”: {
“firstBatch”: [
{
“title”: “Red Sun”,
“rated”: “PG”
},
{
“title”: “The Karate Kid”,
“rated”: “PG”
},
{
“title”: “Dragon Ball Z: Tree of Might”,
“rated”: “PG”
},
{
“title”: “The Transformers: The Movie”,
“rated”: “PG”
},
{
“title”: “Those Magnificent Men in Their Flying Machines or How I Flew from London to Paris in 25 hours 11 minutes”,
“rated”: “G”
},
{
“title”: “Cars”,
“rated”: “G”
},
{
“title”: “Jack and the Beanstalk”,
“rated”: “G”
},
{
“title”: “The Cat Returns”,
“rated”: “G”
},
{
“title”: “Summer Wars”,
“rated”: “PG”
},
{
“title”: “The Secret World of Arrietty”,
“rated”: “G”
},
{
“title”: “The Secret World of Arrietty”,
“rated”: “G”
},
{
“title”: “Life of Pi”,
“rated”: “PG”
},
{
“title”: “Millennium Actress”,
“rated”: “PG”
},
{
“title”: “Whisper of the Heart”,
“rated”: “G”
},
{
“title”: “Defending Your Life”,
“rated”: “PG”
},
{
“title”: “The Goodbye Girl”,
“rated”: “PG”
},
{
“title”: “Local Hero”,
“rated”: “PG”
},
{
“title”: “Babies”,
“rated”: “PG”
},
{
“title”: “In the Shadow of the Moon”,
“rated”: “PG”
},
{
“title”: “Hell in the Pacific”,
“rated”: “G”
},
{
“title”: “Tora! Tora! Tora!”,
“rated”: “G”
},
{
“title”: “Dreams”,
“rated”: “PG”
},
{
“title”: “Empire of the Sun”,
“rated”: “PG”
},
{
“title”: “Hachi: A Dog’s Tale”,
“rated”: “G”
}
],
“id”: NumberLong(“0”),
“ns”: “mflix.movies”
},
“ok”: 1,
“operationTime”: Timestamp(1558454747, 9),
“$clusterTime”: {
“clusterTime”: Timestamp(1558454747, 9),
“signature”: {
“hash”: BinData(0, “d5bE04CT5bYnSobkkz60keGqLoE=”),
“keyId”: NumberLong(“6692152603058372609”)
}
}
}

@pawnalmighty

Did you get Lab 1 “$match” correct? And what is the $toArray intended to do. Don’t post actual code here, but feel free to outline the steps you’re taking. There’s something wrong with your pipeline code.

Hi, @pawnalmighty, I’m having a similar situation here.
I did Lab 1 “$match” correct. The result of my query (including $project) seems to be ok, but once I run validateLab2(pipeline), I get “aggregate failed”.

Hey @diegoseghezzo,

I think pawnalmighty has left the show.
What’s the full error message? Let’s see a screenshot of the error message alone.

Hey @007_jb, I was surrounding the aggregations with single quotes when assigning to the variable, that was the issue :wink:

Like var variable = ‘[my aggregation]’ and should be
var variable = [my aggregation]

1 Like

:slightly_smiling_face: :+1: