0
Aggregation trên Spring boot cực kỳ chậm
Chào mọi người, em có đoạn Aggregation trong spring boot như sau:
@Aggregation(pipeline = {
"{ $match: { 'createdAt': { $gte: ?0, $lt: ?1 } } }",
"{ $lookup: { from: 'UserAccount', localField: 'email', foreignField: 'email', as: 'account' } }",
"{ $lookup: { from: 'Province', localField: 'account.locationId', foreignField: 'locationId', as: 'location' } }",
"{ $group: { _id: { description: { $arrayElemAt: ['$location.description', 0] } }, number: { $sum: 1 } } }",
"{ $project: { province: '$_id.description', number: 1, _id: 0 } }",
"{ $sort: { number: -1 } }"
})
Khi gọi API thì mất khoảng 40s mặc dù chỉ trả về 30 phần tử, nhưng khi gọi aggregate trong Studio 3T thì lại chưa đến 1s:
db.getCollection("SessionMesh").aggregate([
{
$lookup: {
from: "UserAccount",
localField: "email",
foreignField: "email",
as: "account"
}
},
{
$lookup: {
from: "Province",
localField: "account.locationId",
foreignField: "locationId",
as: "location"
}
},
{
$group: {
_id: { description: { $arrayElemAt: ["$location.description", 0] } }, count: { $sum: 1 }
}
},
{
$project: {
province: '$_id.description', count: 1, _id: 0
}
},
{
$sort: {
count: -1
}
}
])
Cho em hỏi tại sao lại có sự khác biệt lớn đến như vậy và cách khắc phục như thế nào ạ. Em xin cảm ơn.
Thêm một bình luận
3 CÂU TRẢ LỜI
vẫn dùng ngon bạn ơi, cơ bản là do cách bạn kia xử lý thôi
0
We have numerous copy clients who appreciate the services we provide as well as those who are Independent Dehradun escorts on our reports. If you'd like to see some of our gorgeous women today, check out our page on profiles.