getting this error while validating
MongoDB Enterprise Cluster0-shard-0:PRIMARY> validateLab1(favorites)
command failed: {
“operationTime” : Timestamp(1615182562, 1),
“ok” : 0,
“errmsg” : “Each element of the ‘pipeline’ array must be an object”,
“code” : 14,
“codeName” : “TypeMismatch”,
“$clusterTime” : {
“clusterTime” : Timestamp(1615182562, 1),
“signature” : {
“hash” : BinData(0,“arjbnV+Pl7utOzi6kz00rRIphdA=”),
“keyId” : NumberLong(“6902062171803353090”)
}
}
} : aggregate failed
validateLab1.js is
var validateLab1 = favoritess => {
let aggregations = db.getSiblingDB(“aggregations”)
if (!pipeline) {
print(“var pipeline isn’t properly set up!”)
} else {
try {
var result = aggregations.movies.aggregate(pipeline).toArray().length
let sentinel = result
let data = 0
while (result != 1) {
data++
result = result % 2 === 0 ? result / 2 : result * 3 + 1
}
if (sentinel === 23) {
print(“Answer is”, data)
} else {
print(“You aren’t returning the correct number of documents”)
}
} catch (e) {
print(e.message)
}
}
}
var favorites = [
“Sandra Bullock”,
“Tom Hanks”,
“Julia Roberts”,
“Kevin Spacey”,
“George Clooney”]
db.movies.aggregate([
{
$match: {
“tomatoes.viewer.rating”: { $gte: 3 },
countries: “USA”,
cast: {
$in: favorites
}
}
},
{
$project: {
_id: 0,
title: 1,
“tomatoes.viewer.rating”: 1,
num_favs: {
$size: {
$setIntersection: [
“$cast”,
favorites
]
}
}
}
},
{
$sort: { num_favs: -1, “tomatoes.viewer.rating”: -1, title: -1 }
},
{
$skip: 24
},
{
$limit: 1
}
])
how to store variable as a reference within the pipeline