標籤:syn max ase var == element 分組 res god
public static void OnQuery_QXData(string DBName, string tablename,string layername)
{
if (ConnectionString == null) OnCreateDB();
MoDataBase = MoClient.GetDatabase(DBName);
var collection = MoDataBase.GetCollection<BsonDocument>(tablename);
//{$group:{_id:{stationID:"$stationID",stationName:"$stationName"},TimeData:{$max:"$TimeData"},eValue:{$last:"$eValue"}}}
var group = new BsonDocument {
{"_id",new BsonDocument
{
{"stationID","$stationID"},
{"stationName","$stationName" }
}
},
//{"stationID",new BsonDocument{ { "stationID", "$stationID" } } },
{"stationID",new BsonDocument("$last","$stationID")},
{ "TimeData",new BsonDocument("$max","$TimeData")},
{"eValue" ,new BsonDocument("$last","$eValue")}
};
var list = collection.Aggregate().Group(group).ToListAsync().Result;
double value = 0.0;
foreach (BsonDocument bsondoc in list)
{
double evalue = double.TryParse(bsondoc.GetElement("eValue").Value.ToString(),out value)?value:0;
string stationid = bsondoc.GetElement("stationID").Value.ToString();
}
}
}
}
C#操作mongodb(彙總函式)-分組找出每組的最大值