Mongodb Aggregate Not working for Map field golang

Viewed 44

So I have two tables. I want to join them and retrieve the map after joining

// First Collection
type configuration struct {
  Id              string             `bson:"_id"`
  Policies        map[string]policy  `bson:"policies"`
}

type policy struct{
  PolicyCount int64                 `bson:"policyCount"`
}

// Second collection

type specialization struct {
    ID               string     `bson:"_id"`
    configId         string     `bson:"configId"// This is mapped to theconfig struct
}

So I want to joint specialization with configuration table and return id from specialization table and policies map from configuration table

This is how my code looks like

    lookupStage := bson.D{{"$lookup", bson.D{{"from", configcollection}, {"localField", "configId"}, {"foreignField", "_id"}, {"as", "retconfig"}}}}
    unwindStage := bson.D{{"$unwind", bson.D{{"path", "$retconfig"}, {"preserveNullAndEmptyArrays", false}}}}
    project := bson.D{{"$project", bson.D{{"_id", 1},
        {"retryPolicies", "$retconfig.value.policies"}
    }}}
  pipeline := mongo.Pipeline{lookupStage,unwindStage, project}
  r.store.Db.Collection("specialization").Aggregate(ctx, pipeline)

I don't know what I have missed but the id is getting retrieved but the policy map is not. Any help in what I have missed will be appreciated

0 Answers
Related