Improve efficiency of first() Method in MongoIterableImpl

XMLWordPrintableJSON

    • Type: Improvement
    • Resolution: Unresolved
    • Priority: Minor - P4
    • None
    • Affects Version/s: None
    • Component/s: Query Operations
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      The current implementation of the first() method in MongoIterableImpl creates a BatchCursor and calls the next() method to retrieve only the first entry. However, underlying readOperation is created with the batch size specified by the user. As a result, a call to the server is made to retrieve documents in batches, even though only the first element is returned by the first() method.

      It leads to inefficient utilization of system resources, including heap memory, and places undue pressure on the server and network. To resolve this issue, it is recommended to optimize the first() method by ensuring that the readOperation is created with a batch size of 1.

            Assignee:
            Unassigned
            Reporter:
            Slav Babanin
            None
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: