Arrays $concatarray仅支持数组,不支持对象

Arrays $concatarray仅支持数组,不支持对象,arrays,mongodb,go,slice,mongo-go,Arrays,Mongodb,Go,Slice,Mongo Go,我试图在Go中编写一个完美工作的MongoDB查询,但我在使用数组时遇到了困难 处理JSON: [ ... { $project: { acl: { $reduce: { input: "$a.accesses", initialValue: [], in: { $concatArrays: [

我试图在Go中编写一个完美工作的MongoDB查询,但我在使用数组时遇到了困难

处理JSON:

[
...
{
    $project: {
        acl: {
            $reduce: {
                input: "$a.accesses",
                initialValue: [],
                in: {
                    $concatArrays: ["$$value", "$$this"]
                }
            }
        }
    }
}]
但不在Go上工作:

pipe := mongo.Pipeline{
    ...
    bson.D{{Key: "$project", Value: bson.M{
        "acl": bson.M{
            "$reduce": bson.M{
                "input":        "$a.accesses",
                "initialValue": bson.M{},
                // None of the below works
                "in": bson.M{"$concatArrays": bson.A{"$$value", "$$this"}},
                // "in": bson.M{"$concatArrays": []interface{}{"$$value", "$$this"}},
                // "in": bson.M{"$concatArrays": [2]string{"$$value", "$$this"}},
                // "in": bson.M{"$concatArrays": []string{"$$value", "$$this"}},
                // "in": bson.M{"$concatArrays": []interface{}{"$$value", "$$this"}},
                // "in": bson.D{{Key: "$concatArrays", Value: []interface{}{"$$value", "$$this"}}},
            },
        },
    }}},
}
错误:
$concatarray仅支持数组,不支持对象


我是Go新手,所以我很确定我在某些地方遗漏了数组的概念。

您为
initialValue
提供的Go值是而不是数组:

"initialValue": bson.M{},
相反,你应该:

"initialValue": []interface{}{},
或:


好的,那就行了!我只是看错了地方。非常感谢你!
"initialValue": bson.A{},