MongoDB.live, free & fully virtual. June 9th - 10th. Register Now

"Unrecognized option to $lookup: let" when i export pipeline to Java

It’s the tips on MongoDB Compass “Unrecognized option to $lookup: let”

 [{
$lookup: {
    from: 'RoleEntity',
    let: {
        anotherRoleId: "$roleId"
    },
    pipeline: [{
            $match: {
                "serverId": 3,
                "lastLoginTime": {
                    $lt: 1588435200000
                },
                "createTime": {
                    $gte: 0,
                    $lte: 1588435199999
                }
            }
        },
        {
            $match: {
                $expr: {
                    $eq: ["$roleId", "$$anotherRoleId"]
                }
            }
        },
    ],
    as: 'roles'
}}, {
$match: {
    "roles": {
        $gt: {
            $size: 0
        }
    }
}}, {
$group: {
    _id: "$curChapterId",
    count: {
        $sum: 1
    }
}}]

How can i query without the ‘let’ label?

The pseudo-SQL statement what i want is:

  SELECT curChapterId,count(*) FROM RleChapterEntity where roleId IN (SELECT roleId from RoleEntity where ...) GROUP BY curChapterId

Very thanks for your help.

There is an open issue for the error you are getting: https://jira.mongodb.org/browse/COMPASS-4111

But, you can still export the pipeline to Java - without the Use Builders option (just not select this check box).

1 Like