case: a table has at least 30 million pieces of data per day. There are thousands of types. Can you now quickly read the maximum values of the day for thousands of types at a time, that is, the last record time of the day? Maybe 15:00. Maybe 23:00. I"m not sure. Try to find out a thousand types in groups as much as possible. Instead of separating each type, sorting it, and then taking the last piece of data.
db.SEC_2018_05_14.aggregate([{ $group: { _id: {dev_id: "$dev_id", data_id: "$data_id"},lastObj: { $last: "$$ROOT" } } } ,
{$project{_id:0,dev_id:"$lastObj.dev_id",data_id:"$lastObj.data_id",data_value:"$lastObj.data_value",fdate:"$lastObj.fdate"}} ]).pretty()
dev_id,data_id,fdate is an index.
fdate is an index.
as above, although it takes five or six seconds to go through the index, I think it will take a lot of time if it is 2.5 million.
is there any good way to find out?