title: Mongo/Java findAndReplace not working
body: <p>I have a Mongo collection like this</p>
  
  <pre><code>email{
  "isConfirmed" : true/[or false]
  "email" : "xxxxxxxxxxx"
  }
  </code></pre>
  
  <p>When I am trying to update the <code>isConfirmed</code> field to true or false, depending on the email which apparently is unique, it takes ages. </p>
  
  <p>The programming language I am using is Java</p>
  
  <p>Here's my code. </p>
  
  <pre><code>List&lt;String&gt; clientEmails = new ArrayList&lt;String&gt;();
  
  Mongo mongoConnection = new Mongo();
  
  DB mongoDatabase = mongoConnection.getDB(DB_NAME);
  
  DBCollection mongoCollection = mongoDatabase.getCollection(COLLECTION_NAME);
  
  int size = clientEmails.size();
  
  for(int i=0;
  i
  &lt;
  size; i++)
  
  {
  
      BasicDBObject query = new BasicDBObject();
  
      System.out.println(clientEmails.get(i).toString());
  
      query.put("email.email", clientEmails.get(i).toString());
  
      BasicDBObject Update = new BasicDBObject("$set", new   BasicDBObject("email.isConfirmed", false));
  
      mongoCollection.update(query, Update); 
  </code></pre>
  
  <p>This one takes ages to run through the collection which consists of around 3500 entries]</p>
  
  <pre><code>  //mongoCollection.findAndModify(query, Update);
  </code></pre>
  
  <p>Even findAndModify doesn't work at all, I am not sure if I am missing something here</p>
  
  <p>However, I have tried with the DBcursor, it works but it takes around 3 minutes to run. </p>
  
  <pre><code>//             DBCursor cursor = mongoCollection.find(query);
  //
  
  //             while(cursor.hasNext()){
  
  //                 BasicDBObject Update = new BasicDBObject("$set", new BasicDBObject("email.isConfirmed", true));
  
  //                 mongoCollection.update(cursor.next(), Update);
  //             }
  </code></pre>
  
  <p>This method takes around 3 minutes. Can someone suggest me of a workaround or something?</p>