Monday, 15 September 2014

java-program is not inserting all data-sets into mongodb-table -



java-program is not inserting all data-sets into mongodb-table -

i have next java-program, should insert 2 records in table testcoll:

package mongodbtest; import java.net.unknownhostexception; import com.mongodb.basicdbobject; import com.mongodb.db; import com.mongodb.dbcollection; import com.mongodb.mongo; public class hellomongodb { public static void main(string[] args) { mongo mongo = null; db db=null; dbcollection table=null; // connection mongodb-server seek { mongo = new mongo("localhost", 27017); } grab (unknownhostexception e) { e.printstacktrace(); } //insert info db = mongo.getdb("testdb"); table = db.getcollection("testcoll"); //create document , insert basicdbobject document = new basicdbobject(); document.put("name", "andre"); document.put("age", 34); basicdbobject document2 = new basicdbobject(); document2.put("name", "beatrix"); document2.put("age", 19); table.insert(document); table.insert(document2); } }

like can see, should insert 2 records collection testcoll, insert first one.

> db.testcoll.find() { "_id" : objectid("54369b986d4b35dd1125e7ea"), "name" : "andre", "age" : 34 }

any suggestions?

greetings, andre

there no problem code. can add together list of objects this!!!

java mongodb insert

No comments:

Post a Comment