The grouping of mongodb to find the maximum value, the quantity is too large, time-consuming optimization?

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?

Mar.11,2021

Please go to the backstage of the official account of Wechat in Mongoing Chinese community to get the way to join the communication group, and to communicate within the group

.
  • What if mongo queries count very slowly?

    I currently have a query using mongodb3.4, that needs to be paged. Paging needs to return the total number and number of pages. but that s the problem. Paging queries are fast, but counting is slow . The count statement is as follows: db.message.fin...

    Mar.04,2021
  • How to clean up the contents of journal in mongodb,

    how can I delete the files under the journal file of mongodb? produced a lot of tables before, so some were deleted, but this folder still has more than 60 gigabytes, which is much larger than the size of the existing tables. how to clean it up? ...

    Mar.13,2021
  • The problem of multithreading accessing mongodb

    in java, mongodb is operated by multiple threads. uses mongoTemplate as an operation. then, there are more than five hundred threads to operate on the mongodb. then, it was found that none of the 500-plus threads had to create a new mongodb connection...

    Mar.13,2021
  • Error report on importing mongodb in python

    raceback (most recent call last): File " home shenjianlin .local lib python3.4 site-packages twisted internet defer.py", line 653, in _runCallbacks current.result = callback(current.result, *args, **kw) File " home shenjianlin my_pr...

    Aug.22,2021
  • How to select an index when querying with mongo

    problem description There are two indexes in mongo, the first is a single-field index of the {_ id} field, and the second index is a composite index composed of {chat_id, _ id}. When I use the query db.collection.find ({ "chat_id ": ObjectId ( "* ")...

    Sep.08,2021
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b35bc9-2b505.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b35bc9-2b505.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?