MongoServerError: unknown operator: $map

Hello,

When using ubunut 20.04 bundled mongo client,
$map seemed to be a problem.
And using mongosh instead, I also met the same issue.
Any suggestions ??
Optional Material is very good.
But $map operator exists ??

Using MongoDB: 4.2.14
Using Mongosh Beta: 0.15.5

Enterprise Cluster0-shard-0 [primary] aggregations>

Enterprise Cluster0-shard-0 [primary] aggregations> db.movies.aggregate([
… { $match :{
… writers: {
… $map: {
… input: “$writers”,
… as: “writer”,
… in: “$$writer”
… }
… }}},
… {
… $project : {
… writers : 1,
… cast : 1
… }
… }
… ]).pretty()
MongoServerError: unknown operator: $map
Enterprise Cluster0-shard-0 [primary] aggregations> db.movies.find(
… {
… writers: {
… $map: {
… input: “$writers”,
… as: “writer”,
… in: “$$writer”
… }
… }},
… {

… writers : 1,
… cast : 1

… }
… ).pretty()
MongoServerError: unknown operator: $map

Regards,
Steven

Hi Steven,

$map aggregation expression is only available in $project and $addToSet stages. It looks like you are trying to use it in $match stage which is not supported, as far as I know. Same with .find() MQL API.

Thanks,
Mahi

2 Likes

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.