How does mongoose handle a multi-tier circular query, modify the query results, and then return the final results?

problem description

there is a shopping cart cartList field under the user table. The field type is as follows:

cartList: [
    {
        shopId: {
            type: Schema.ObjectId
        },
        shopName: String,
        goodsList: [
            {
                _id: Schema.ObjectId,
                name: String,
                num: Number,
                selectedAttr: Array
            }
        ]
    }
]

then make a supplement to the price before taking this field. Here will involve two loops, one is to traverse the elements in the cartList, and the second is to traverse the goodsList array in the elements, and use the _ id inside to find the price in the goods table and add it. So the question is, because find queries are asynchronous, how can I get the correct results at the end of the loop?


mongoose find has a callback, or promise . If you have found the result, just implement the business logic in the callback.
reference

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-1e9bebd-4765b.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-1e9bebd-4765b.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?