MongoDB server side pagination with lookup, inner join and limit

Data:
I have MongoDB setup to hold information about different devices. Each device can contain multiple nodes which have parent-child relationship. Each device can be applicable to multiple platforms and releases.

Expected functionality:
User should be able to search for a part of the text and view all the devices which have such node names and all platform, releases they are applicable to. User should also be able to filter the result for a few platforms/releases.

Sample data:

  1. release collection:
{
device_id:"7f96a17585f028ae13bd0d1a390461e9", 
device-name:"apts26v", 
platform:"bj5000", 
release:"10.0"
}
{
device_id:"7f96a17585f028ae13bd0d1a390461e9", 
device-name:"apts26v", 
platform:"bj5000", 
release:"10.5"
}
{
device_id:"7f96a17585f028ae13bd0d1a390461e9", 
device-name:"apts26v", 
platform:"rex9000", 
release:"10.5"
}
  1. node collection:
{
device_id:"7f96a17585f028ae13bd0d1a390461e9",
text:"tree-node", 
xpath:"/module/active/tree-node"
}

Index:

  1. I have an index in release collection for device id, platform and release
  2. I have a text index in node collection for text

Amount of documents:
The database holds large amount of data and the quantity is expected to increase further.

  1. release collection has around 400k documents
  2. node collection has around 35 million documents

Approach 1:
Getting all the results for search string provides timeout error. So I decided to perform server side pagination and get only 50 rows at a time. If I simply perform a search on node collection and limit to 50 rows, the query is working fine. But when I perform a lookup with release collection, remove the rows which do not have selected platform and release, and then limit by 50 rows, the query provides timeout error.

Approach 2:
If I perform the filtering of platform and release after the limit stage, results are returned but with different number of documents in each page. If in the first 50 query results, if only 10 are applicable to the selected platform and release, the first page will have only 10 entries.

Aggregation:

node.aggregate([
{
      "$match": {
                  "text":{
                    "$regex":search_text,
                    "$options":"i"
                  }
                }
            },
            { "$sort": { "device_id": 1 ,"text":1} },
            {
                  "$lookup": {
                        "from": "release",
                        "let": { "deviceId": "$device_id" },
                        "pipeline": [
                              { 
                                    "$match": {
                                          "platform": "rex9000",
                                          "release":"10.5",
                                          "$expr": { "$eq": [ "$$deviceId", "$device_id" ] }
                                    }
                              }
                        ],
                        "as": "releasePlatformInfo"
                  }
            },
            {
                  "$match": {
                        "releasePlatformInfo": {"$ne": []}
                  }
            },
            {"$skip": 0},
            {"$limit": 50}
        ])

How should I sort this out? Should I can resolve this by changing the aggregation query or restructuring the data? Please give me your suggestions.

2

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật