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 # Operations MongoDB (aggregate function)-Grouping to find the maximum value per group