MongoServerError: let not supported database is on Azure

const dashboard = await AdminDataModel.aggregate([
            {
                $match: {
                  ...keyword
                }
              },
            {
                $lookup: {
                    from: "saveData",
                    let: {
                        cadmin_id: "$_id"  
                    },

                    pipeline: [
                        {
                            $match: {
                                $expr: {
                                    $eq:
                                        ["$c_id", "$$cadmin_id"]   
                                }
                            }
                        },
                    ],
                    as: "sadmin"
                }
            },
            {
                $lookup: {
                    from: "users",
                    let: {
                        cadmin_id: "$_id"
                    },
                    pipeline: [
                        {
                            $match: {
                                $expr: {
                                    $eq:
                                        ["$c_id", "$$cadmin_id"]
                                }
                            }
                        }
                    ],
                    as: "Datauser"
                }
            },

            {
                $lookup: {
                    from: "workflows",
                    let: {
                        cadmin_id: "$_id"
                    },
                    pipeline: [
                        {
                            $match: {
                                $expr: {
                                    $eq:
                                        ["$c_id", "$$cadmin_id"]
                                }
                            }
                        }
                    ],
                    as: "workflow"
                }
            },         
        ])

When i run this code on Azure cosmos it show an error
" MongoServerError: let not supported "

As far as I know Cosmos will always be behind feature wise compared to local instance or Atlas.

In the code you shared you do not need the let:/pipeline: feature.

All your $lookup stages could forgo the let:/pipeline: and simply use localField:_id and foreignField:c_id.

1 Like

Hello Sir,
your previous answer solve my 1 one problem
Please again help… if we have let/pipeline inside $lookup which is inside pipeline
code is below: what should i dow
$lookup: {

                from: "sadmins",

                let: {

                    cadmin_id: "$_id"

                },

                pipeline: [

                    {

                        $match: {

                            $expr: {

                                $eq:

                                    ["$c_id", "$$cadmin_id"]

                            }

                        }

                    },

                    {

                        $match: {

                          ...keyword

                         }

                     },

                    {

                        $lookup: {

                            from: "users",

                            let: { sadmin_id: "$_id" },

                            pipeline: [

                                {

                                    $match: {

                                        $expr: {

                                            $eq:

                                                ["$s_id", "$$sadmin_id"]

                                        }

                                    }

                                }

                            ],

                            as: "user"

                        }

                    },

                   

                    {

                        $lookup: {

                            from: "workflows",

                            let: {sadmin_id: "$_id"},

                            pipeline: [

                                {

                                    $match: {

                                        $expr: {

                                            $eq:

                                                ["$s_id", "$$sadmin_id"]

                                        }

                                    }

                                }

                            ],

                            as: "workflow"

                        }

                    },

                     

                    {

                        $project: {

                            _id: 1, user_name: 1, email: 1, phone: 1, logo: 1, sadmin: 1, address: 1, state: 1, country: 1, pin: 1,

                            loginValue:1,profilePath:1,total_user: { $size: "$user" },

                            total_workflow: { $size: "$workflow" }

                        }

                    }

                ],

                as: "sadmin"

            },

As mentioned in my previous post

Look at the examples from the $lookup documentation that use localField and foreignField.

1 Like

Hi @Avish_Pratap_Singh,

Cosmos’s MongoDB API is an independently developed emulation of a subset of MongoDB server features. Some features (like $lookup) are significantly behind their genuine counterparts in MongoDB server releases and others are missing entirely.

The Cosmos API version 4.2 documentation notes this incomplete $lookup implementation:

The $lookup aggregation does not yet support the uncorrelated subqueries feature introduced in server version 3.6. You will receive an error with a message containing let is not supported if you attempt to use the $lookup operator with let and pipeline fields.

MongoDB 3.6 was first released in 2017. If you want to use modern MongoDB features on Azure, I recommend looking into MongoDB Atlas on Azure: How To Run MongoDB Atlas On Microsoft Azure | MongoDB.

Even if you decide you prefer to use Cosmos’ API, you can use the Atlas free tier to compare behaviour with a genuine MongoDB server to determine whether an issue might be due to differing server implementations rather than your usage or syntax.

Regards,
Stennie

1 Like

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