Hello,
I've been doing program conversion from (PHP) to go-lang for the past 4 days just so I can learn "golang" in a short period of time
while still being productive. So forgive me if my question is leaning towards how to express MongoDB aggregation concepts in "go".
I have this aggregation query:
{ $match: { "vh.pt_id" : {$gt: 0}} },
_id: {$concat: [{$substr: ["$vh.pt_id",0,-1]}, "_", {$substr: ["$vh.vdid",0,-1]}, "_", "$vh.vvl"]},
yids: {$first: "$vh.yids"},
yvls: {$first: "$vh.yvls"},
pt_id: {$first: "$vh.pt_id"},
mkid: {$first: "$vh.mkid"},
mdid: {$first: "$vh.mdid"},
sbid: {$first: "$vh.sbid"},
eid: {$first: "$vh.eid"},
leid: {$first: "$vh.leid"},
{ $out: "tmp_ptvh_map_stage2"}
and my current code is:
bson.M{"$match" : bson.M{"vh.pt_id"} : bson.M{"$gt" : 0}},
bson.M{"$group" : bson.M{
bson.M{"$substr" : ???????}
"yids" : bson.M{"$first" : "$vh.yids"},
"yvls" : bson.M{"$first" : "$vh.yvls"},
"pt_id" : bson.M{"$first" : "$vh.pt_id"},
"mkid" : bson.M{"$first" : "$vh.mkid"},
"mdid" : bson.M{"$first" : "$vh.mdid"},
"sbid" : bson.M{"$first" : "$vh.sbid"},
"eid" : bson.M{"$first" : "$vh.eid"},
"leid" : bson.M{"$first" : "$vh.leid"},
I really don't know how to express the following lines to go/mgo/bson:
_id: {$concat: [{$substr: ["$vh.pt_id",0,-1]}, "_", {$substr: ["$vh.vdid",0,-1]}, "_", "$vh.vvl"]},
I'm stuck with these:
"_id" : bson.M{
"$concat" : []bson.D{
bson.M{"$substr" : ???????}
}
},
With my limited go-lang knowledge, I know that arrays and slice will only accept one data type. But I'm sure how to fully express
{$substr: ["$vh.pt_id",0,-1]}
into go/mgo/bson:
bson.M{"$substr": []?????}
Thanks in advance!
Regards,
Raul