Expected ‘pipeline’ to be a BSON document (or equivalent), but instead turned out to be primitive. (MongoDB Driver) – Getting Help

Hello fella gopher! I’m trying to nest a pipeline inside a $lookup step in MongoDB 5 using the Go driver, but I get this error:

"(AtlasError) Expected 'pipeline' to be BSON docs (or equivalent), but got primitive.D instead. Doc = [{from post} {localField translated_version} {foreignField _id} {pipeline [{$project [{slug 1}]}]} {as translated_version}]"

my code:

    lookup_translated_post := bson.D{
        {
            Key: "$lookup", Value: bson.D{
                {
                    Key: "from", Value: model_name,
                },
                {
                    Key: "localField", Value: "translated_version",
                },
                {
                    Key: "foreignField", Value: "_id",
                },
                {
                    Key: "pipeline", Value: bson.D{
                        {
                            Key: "$project", Value: bson.D{
                                {
                                    Key: "slug", Value: 1,
                                },
                            },
                        },
                    },
                },
                {
                    Key: "as", Value: "translated_version",
                },
            },
        },
    }

I don’t understand what am I doing wrong Already tried to get help from mongo community but got no response


Leave a Comment