I am trying aggregate query in mongo database.
I could find the command for aggregate in command line as well in robomongo.
Please find query below
db.portfolio.aggregate([
{ $match: {id: "c-4fbfd8ed-8b4a-4cf6-b3e0-2f5f3200d6d4"}},
{ $project: {
medias: {$filter: {
input: '$medias',
as: 'category',
cond: {$eq: ['$$category.categoryId', "j_664e2bba-fa0e-4d31-aa26-732b92c1b872"]}
}}
}}
])
But when I tried to convert into BSONDocument and run it, it throws an error during runtime. The equivalent BSONDocument that I have added in my code is
val commandDoc = BSONDocument(
"aggregate" -> "portfolio", // we aggregate on collection `portfolio`
"pipeline" -> BSONArray(
BSONDocument("$match" -> BSONDocument("id" -> portfolioId)),
BSONDocument(
"$project" -> BSONDocument(
"medias" -> BSONDocument(
"$filter" -> BSONDocument(
"input" -> "$medias",
"as" -> "category",
"cond" -> BSONDocument(
"$eq" -> Json.arr("$$category.categoryId", categoryId)
)
)
)
)
)
)
)
the error which gives when I am debugging the code during runtime is
The 'cursor' option is required, except for aggregate with the explain argument
What should I required to resolve this issue. I am using mongo version 3.6.2, is it can be issue with version because when I tried with mongo 3.2.7 it was working perfectly well.