I wanted to add all of the ID's inside of MongoDB to an array with using Java. How do I take ID's or any data form and put in an array from JAVA?
PS: I'm newbie with nosql database structure and I'm using MongoDb 3.2
Code is so far something like this.
public void ArrayEx(){
MongoClient mongoClient = new MongoClient("localhost",27017);
MongoDatabase database = mongoClient.getDatabase("dbTest");
MongoCollection<Document> collection =database.getCollection("colTest");
MongoCursor<Document> cursor = collection.find().iterator();
while(cursor.hasNext()) {
//What should I add here?
}
}
long[]of_id?MongoCursor<Document> cursor = collection.find().projection(new Document("_id", 1)).iterator(); while(cursor.hasNext()) { Document result = cursor.next(); Long id = result.getLong("_id"); // add to combobox }