if i give name in my programm i need to get the age with corresponding age also {"Name":"msr","age" :24} like these
package mongojava; import com.mongodb.BasicDBObject; import com.mongodb.DB; import com.mongodb.DBCollection; import com.mongodb.DBCursor; import com.mongodb.DBObject; import com.mongodb.MongoClient; public class javaconn { public static void main(String[] args) { MongoClient client = new MongoClient("localhost",27017); DB db = client.getDB( "admin" ); DBCollection collection = db.getCollection("admin"); DBObject dbo = collection.findOne(); //String name = (String) dbo.get("Name"); //String age = (String) dbo.get("age"); BasicDBObject query = new BasicDBObject(); query.put("Name", "Siddareddy"); DBCursor cursor = collection.find(dbo); BasicDBObject newDocument = new BasicDBObject(); newDocument.put("age", "24"); while (cursor.hasNext()) { System.out.println(cursor.next()); } } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)