I have the following java-program, that should insert 2 records in the 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 to the MongoDB-Server
try {
mongo = new Mongo("localhost", 27017);
} catch (UnknownHostException e) {
e.printStackTrace();
}
//insert data
db = mongo.getDB("testdb");
table = db.getCollection("testcoll");
//create document and 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 you can see, it should insert 2 records into the collection testcoll, but it only insert the first one.
> db.testcoll.find()
{ "_id" : ObjectId("54369b986d4b35dd1125e7ea"), "name" : "Andre", "age" : 34 }
Any suggestions?
Greetings, Andre