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

FindIterable<Document>'s iterator () method, Iterator query problem

    XMLWordPrintableJSON

Details

    • Icon: Question Question
    • Resolution: Done
    • Icon: Major - P3 Major - P3
    • None
    • None
    • None
    • None
    • Hide

      1. What would you like to communicate to the user about this feature?
      2. Would you like the user to see examples of the syntax and/or executable code and its output?
      3. Which versions of the driver/connector does this apply to?

      Show
      1. What would you like to communicate to the user about this feature? 2. Would you like the user to see examples of the syntax and/or executable code and its output? 3. Which versions of the driver/connector does this apply to?

    Description

      summarize

      When I was using Mongo Driver Java 4.9, I checked everything and when I iterated, it took two seconds for ten thousand pieces of data, which was too slow

       

      How to reproduce

      I used the collection. find() method and returned the FindIterable<Document>class. I used the iterator() method in this class to iterate and queried 10000 pieces of data. The results were converted for two seconds, and I will paste the code out

       

       
      Public static List<Map<String, Object>>convertDocumentToMap (FindIterable<Document>iterable, Integer count){
       
      Long queryAction=System. currentTimeMillis();
       
      System. out. println ("Creation start time:"+queryAction);
       
      List<Map<String, Object>>resultList=new ArrayList<>(count);
       
      Long queryEnd=System. currentTimeMillis();
       
      System. out. println ("Creation end time:"+queryEnd);
       
      System. out. println ("Creation time:"+(queryEnd queryAction));
       
      Try (MongoCursor<Document>cursor=iterable. iterator()){
       
      Long action=System. currentTimeMillis();
       
      System. out. println ("Cycle start time:"+action);
       
      While (cursor. hasNext())
       
       
       
      {resultList. add (cursor. next());}
       
      Long end=System. currentTimeMillis();
       
      System. out. println ("Loop end time:"+end);
       
      System. out. println ("Loop time:"+(end action));
       
      }
       
      Return resultList;
       
      }
      

      Attachments

        Activity

          People

            Unassigned Unassigned
            j15030047216@163.com chaoyang jia
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: