I am fairly new to MongoDB and i've got an issue on how to store data from an Array into a mongodb database? For some reason when i implement the following code i get a lot of errors.
private void storeData(String[] trainSeats, String[] customerName, String[] traincustomerSeats){
MongoClient dbb = new MongoClient("localhost", 27017);
DB dbs = dbb.getDB("Train Customers and Seats");
DBCollection coll1 = dbs.getCollection("CW1");
DBCollection coll2 = dbs.getCollection("CW2");
DBCollection coll3 = dbs.getCollection("CW3");
BasicDBObject oneDoc = new BasicDBObject();
for (int k = 1; k < trainSeats.length; k++){
oneDoc.append(String.valueOf(k), trainSeats[k]);
}
coll1.insert(oneDoc);
BasicDBObject twoDoc = new BasicDBObject();
for(int k = 1; k < customerName.length; k++){
twoDoc.append(String.valueOf(k), customerName[k]);
}
coll2.insert(twoDoc);
BasicDBObject threeDoc = new BasicDBObject();
for(int k = 1; k < traincustomerSeats.length; k++){
threeDoc.append(String.valueOf(k), traincustomerSeats[k]);
}
coll3.insert(threeDoc);
optionEnter(trainSeats,customerName,traincustomerSeats);
}
Here are the errors i get when i run the above code:
