My mongo File is here
db.aaa.aggregate([{
$match : {
status : "Active"
}
}, {
$project : {
_id : 1,
title : 1,
postdatetime : 1,
status : 1,
answer : {
$filter : {
input : "$answer",
as : "answe",
cond : {
$eq : ["$$answe.status", "Active"]
}
}
}
}
}
])
I try this one to write in go
o2 := bson.M{
"$project":bson.M{
"$answer":bson.M{
"_id":1,"title":1,"postdatetime":1,"status":1,"answer":bson.M{
"$filter":bson.M{"input":"$answer","as":"ans","cond":bson.M{"$eq":bson.M["$$ans.status","Active",],},}
},
},
},
}
But it show this on err syntax error: unexpected comma, expecting ]
Please Help me Out.
After the answer i try this one
o2: = bson.M {
"$project": bson.M {
"$answer": bson.M {
"_id": 1,
"title": 1,
"revision": 1,
"bgimageurl": 1,
"author": 1,
"postdatetime": 1,
"status": 1,
"qatags": 1,
"followers": 1,
"qaviews": 1,
"answer": bson.M {
"$filter": bson.M {
"input": "$answer",
"as": "ans",
"cond": bson.M {
"$eq": "[$$ans.status][,Active]",
},
},
},
},
},
}
This time compile successfully but after running the go file send me this err msg 2016/05/11 11:04:17 $expressions are not allowed at the top-level of $project exit status 1