package mgodb import ( "context" "eta/eta_forum_admin/utils" "go.mongodb.org/mongo-driver/bson" "go.mongodb.org/mongo-driver/mongo/options" ) func GetEdbDataCalculateByEdbInfoId(edbInfoId int) (items []*EdbDataBase, err error) { findOptions := options.Find() db := NewMgo(utils.MONGODB_COMMUNITY, "edb_data_calculate", MgoClient) filter := bson.D{{"edb_info_id", edbInfoId}} ctx := context.TODO() cur, err := db.Find(filter, findOptions) if err != nil { return } // Close the cursor once finished defer cur.Close(ctx) for cur.Next(ctx) { // create a value into which the single document can be decoded var elem EdbDataBase err = cur.Decode(&elem) if err != nil { return } items = append(items, &elem) } if err = cur.Err(); err != nil { return } return } // GetEdbCalculateDataList 获取指标的数据(日期正序返回) func GetEdbCalculateDataList(endInfoId int, startDate, endDate string) (list []*EdbDataBase, err error) { findOptions := options.Find() findOptions.SetSort(bson.D{{"data_time", 1}}) db := NewMgo(utils.MONGODB_COMMUNITY, "edb_data_calculate", MgoClient) filter := bson.D{{"edb_info_id", endInfoId}} if startDate != "" { filter = append(filter, bson.E{"data_time", bson.M{"$gte": startDate}}) } if endDate != "" { filter = append(filter, bson.E{"data_time", bson.M{"$lte": endDate}}) } ctx := context.TODO() cur, err := db.Find(filter, findOptions) if err != nil { return } // Close the cursor once finished defer cur.Close(ctx) for cur.Next(ctx) { // create a value into which the single document can be decoded var elem EdbDataBase err = cur.Decode(&elem) if err != nil { return } list = append(list, &elem) } if err = cur.Err(); err != nil { return } return }