Mongodb nested documents count how to realize the record of the latest date of each classification or the maximum value of a field in the array.

problem description

there are the following collection,. I need to group statistics according to the name quote.sign field, fetch the latest record according to the last_updated time, or extract the data in the existing format according to the maximum value of quote.price in the whole table.

{
    "_id" : ObjectId("5bfd20dc8e01a44a64c9a455"),
    "name" : "test",
    "last_updated" : ISODate("2018-11-27T10:47:03.000Z"),
    "quote" : [ 
        {
            "price" : 0.00362,
            "volume" : 172.952,
            "last_updated" : ISODate("2018-11-27T10:47:03.000Z"),
            "sign" : "CNY"
        }, 
        {
            "price" : 0.0000346,
            "volume" : 1.6559,
            "last_updated" : ISODate("2018-11-27T10:47:03.000Z"),
            "sign" : "USD"
        }, 
        {
            "price" : 0.00369,
            "volume" : 176.591,
            "last_updated" : ISODate("2018-11-27T10:47:03.000Z"),
            "sign" : "USDT"
        }
    ]
},
{
    "_id" : ObjectId("5bfd20dc8e01a44a64c9a455"),
    "name" : "test1",
    "last_updated" : ISODate("2018-11-27T10:47:03.000Z"),
    "quote" : [ 
        {
            "price" : 0.00362,
            "volume" : 172.952,
            "last_updated" : ISODate("2018-11-27T10:47:03.000Z"),
            "sign" : "CNY"
        }, 
        {
            "price" : 0.0000346,
            "volume" : 1.6559,
            "last_updated" : ISODate("2018-11-27T10:47:03.000Z"),
            "sign" : "USD"
        }, 
        {
            "price" : 0.00369,
            "volume" : 176.591,
            "last_updated" : ISODate("2018-11-27T10:47:03.000Z"),
            "sign" : "USDT"
        }
    ]
}
Dec.20,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-1b3dbff-40946.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-1b3dbff-40946.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?