Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/mongodb/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/go/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Group by调用另一个函数,根据golang mongodb中的Group by元素对文档进行计数_Mongodb_Go - Fatal编程技术网

Group by调用另一个函数,根据golang mongodb中的Group by元素对文档进行计数

Group by调用另一个函数,根据golang mongodb中的Group by元素对文档进行计数,mongodb,go,Mongodb,Go,我使用golang作为Mongodb的后端 我的mongodb收藏是 **employee** { _id:ObjectId(), "emp_name":"qwert", "emp_id":111, "emp_dept":"XYZ" "qualification":"PHD", "employee_status"

我使用golang作为Mongodb的后端

我的mongodb收藏是

**employee**
{
  _id:ObjectId(),
  "emp_name":"qwert",
  "emp_id":111,
  "emp_dept":"XYZ"
  "qualification":"PHD",
   "employee_status":"working"
}
{
_id:ObjectId(),
  "emp_name":"asdfg",
  "emp_id":121,
  "emp_dept":"XYZ"
 "qualification":"MBA"
 "employee_status":"working"
}
**department**
{
    _id:ObjectId(),
    "dept_id":11,
    "dept_name":"XYZ",
    "description":"decs",
    "department_status":"active"
    }
我的密码是

 type DepartmentInfo struct {
    DepartmentID    int                `json:"dept_id" bson:"dept_id"`
    DepartmentName  string             `json:"dept_name" bson:"dept_name"` 
    Description     string             `json:"description" bson:"description"` 
    EmployeeCount   int                `json:"employee_count" bson:"employee_count"`
}

collection := session.DB("db").C("employee")
pipeline := collection.Pipe([]bson.M{
        {"$match": bson.M{ "qualification": "PHD", }},
        {"$group": bson.M{"_id": "$emp_dept",
                "total_employee": bson.M{"$sum": GetDepartmentEmployeeCount("$emp_dept")},                         }},
        {"$lookup": bson.M{
        "from":         "department",
        "localField":   "_id",
        "foreignField": "dept_name",
        "as":           "department_info",
    }},
     {"$unwind": "$department_info"},
     {"$match": bson.M{"$or": []interface{}{
        bson.M{"department_info.status": bson.M{"$exists": false}},
        bson.M{"department_info.status": 1}, // department 1 means active
    }}},   
    })
var departmentInfo [] Department
err = pipeline.All(&departmentInfo)
其他功能为

func GetDepartmentEmployeeCount(var interface{})(int res)
{
  ......
  return res
}

当我在
GetDepartmentEmployeeCount
函数中获得
emp\u dept
时,它会像字符串一样打印它,而不是像
emp\u dept
那样获取值。我想执行类似
select count(*)的查询从employee where emp_dept='var'
。我的问题是如何让另一个函数中的group by元素执行查询?

能否澄清您希望看到的输出?你现在得到了什么?