I have the following code but I am stuck in getting the the counts of likes as I get nil
result.
package main
import (
"fmt"
"gopkg.in/mgo.v2"
"gopkg.in/mgo.v2/bson"
"os"
)
func main() {
uri := "mongodb://root:tempyml@localhost:27017"
sess, err := mgo.Dial(uri)
if err != nil {
fmt.Printf("Can't connect to mongo, go error %v
", err)
os.Exit(1)
}
defer sess.Close()
sess.SetSafe(&mgo.Safe{})
collection := sess.DB("visibl_dev").C("user_videos")
pipe := collection.Pipe([]bson.M{{"$project": bson.M{"likes": 1,
"likeCount": bson.M{"$size": "$likes"}}}})
result := []bson.M{}
err = pipe.All(&result)
if err != nil {
//handle error
}
fmt.Println(result)
}