Uploaded image for project: 'Java Driver'
  1. Java Driver
  2. JAVA-5067

Improve efficiency of first() Method in MongoIterableImpl

    XMLWordPrintableJSON

Details

    • Icon: Improvement Improvement
    • Resolution: Unresolved
    • Icon: Minor - P4 Minor - P4
    • None
    • None
    • Query Operations
    • None

    Description

      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.

      Attachments

        Activity

          People

            Unassigned Unassigned
            slav.babanin@mongodb.com Slav Babanin
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated: