在mongo聚合中,可以使用golang類型 agg := []map[string]interface{}{ map[string]interface{}{ "$project": map[string]interface{}{ "fileName":1, "fileType":1, "fileData":1, "subtractDate": map[string]interface{}{ "$trunc": map[string]interface{}{ "$divide": []interface{}{ map[string]interface{}{ "$subtract": []interface{}{time.Now(), "$creationDate"}, }, 1000*60*60*24, }, }, }, }, }, map[string]interface{}{ "$match": map[string]interface{}{ "subtractDate": 365, }, }, } 只需將聚合選項放在集合的聚合方法中 cur, err := DB.Collection("collectionName").Aggregate(context.TODO(), agg)if err != nil { log.Println(err.Error())} 然后獲取結果