title: mongodb - java get field value
body: <pre><code>{ "_id" : 0, "cityname" : "tallinn", "JAN" : -3 }
  
  { "_id" : 1, "cityname" : "beijing", "JAN" : -5 }
  
  { "_id" : 2, "cityname" : "berlin", "JAN" : 12 }
  
  { "_id" : 3, "cityname" : "buenose", "JAN" : 23 }
  </code></pre>
  
  <p>I want to calculate distance between tallinn to other cities and beijing to other cities its continue to entire document </p>
  
  <p>this is my java code</p>
  
  <pre><code>try {
      BasicDBObject query = new BasicDBObject();
      BasicDBObject select = new BasicDBObject();
      select.put("JAN",1);
      select.put("_id",1);
      DBCursor cursor = coll.find(query,select);
      BasicDBObject obj = (BasicDBObject)cursor.next();
      int m,id;
      id=Integer.parseInt(obj.getString("_id"));
      for (int j=0;j&lt;4;j++){
          m= Integer.parseInt(obj.getString("JAN"));
              if (id==j){
                  while (cursor.hasNext()) {
                      int ma;
                      BasicDBObject object = (BasicDBObject)cursor.next();
                      ma= Integer.parseInt(object.getString("JAN"));
                      System.out.print((m-ma)+"  ");
                  }
          }
      }
  }
  catch (MongoException e){
      System.out.println(e.getClass().getCanonicalName());
  }
  </code></pre>
  
  <p>output </p>
  
  <pre><code> 2 -9 -26
  </code></pre>
  
  <p>I expect this type of output</p>
  
  <pre><code>0 2 -15 -26
  -2 0 -17 -28
  15 17 0 -11
  26 28 11 0
  </code></pre>