SQL query in MongoDB -
i want simple thing eclipse wont let me use find() method, cant see why cuz way explained @ mongodb.org.. can see im doing wrong? folk.find() method, works long dont put condition in there( namn:"robert")
mongo mongo= new mongo(); db db = mongo.getdb("helly"); long starttime= system.currenttimemillis(); dbcollection folk = db.getcollection("folk"); basicdbobject document = new basicdbobject(); document.put("namn", "robert"); document.put("efternamn", "brismo"); document.put("ålder", 34); basicdbobject documentdetail = new basicdbobject(); documentdetail.put("ålder", 47); documentdetail.put("hårfärg", "brun"); documentdetail.put("skostorlek", "44"); document.put("utseende", documentdetail); folk.insert(document); dbcursor cursor= folk.find({namn:"robert"}); while(cursor.hasnext()){ dbobject obj=cursor.next(); system.out.println(obj);}
to find query on namn
, need use instance of basicdbobject
, use query:
basicdbobject query = new basicdbobject("namn", "robert"); dbcursor cursor= folk.find(query); try { while(cursor.hasnext()) { // .. system.out.println(cursor.next()); } } { cursor.close(); }
Comments
Post a Comment