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

XMLWordPrintableJSON

    • Type: Question
    • Resolution: Done
    • Priority: Major - P3
    • None
    • Affects Version/s: None
    • Component/s: 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?
    • None
    • None
    • None
    • None
    • None
    • None

      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;
      
      }
      

            Assignee:
            Unassigned
            Reporter:
            chaoyang jia
            None
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: