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

Improve efficiency of first() Method in MongoIterableImpl

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

      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 Unassigned
            Reporter:
            slav.babanin@mongodb.com Slav Babanin
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: