减少聚合查询时间

发布于 2025-01-20 08:44:31 字数 409 浏览 2 评论 0原文

我是 mongodb 的初学者。我正在研究两个集合预订和预订日志。我有大约 7000 个预订和 14000 个 booking_logs。

我想使用他们的日志进行预订,其中 booking_logs 存在于预订中。我使用了以下查询。

db.bookings.aggregate([
{$lookup:{
    "from":"booking_logs",
    "localField":"_id",
    "foreignField":"booking_id",
    "as":"booking_time_logs"
    }},
{"$match":{"booking_time_logs":{"$not":{"$size":0}}}}
])

但是,查询执行时间太长。有什么办法可以减少时间吗?请回答。谢谢你!

I am a beginner in mongodb. I am working on two collections bookings and booking_logs. I have around 7k bookings and 14k booking_logs.

I want to get booking with their logs for which booking_logs exist with bookings. I have used the following query.

db.bookings.aggregate([
{$lookup:{
    "from":"booking_logs",
    "localField":"_id",
    "foreignField":"booking_id",
    "as":"booking_time_logs"
    }},
{"$match":{"booking_time_logs":{"$not":{"$size":0}}}}
])

But, the query is taking too much time to execute. Is there any way to reduce the time? Please answer. Thank you!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文