Javaを使用してMongoDB内のすべてのIDを配列に追加したいと考えました。どのように私はIDまたは任意のデータ形式を取って、Javaから配列に入れますか?JavaでMongoDBの配列にすべてのIDを追加
PS:私はNoSQLのデータベース構造で初心者だと私はMongoDBの3.2
コードを使用していますが、これまでこのようなものです。
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?
}
}
をあなたは '長い[]'を持つようにしたいです'_id'の? –
私は配列の中にすべての_idを置いて、そのコンボボックスを作ることができます。 –
'MongoCursor cursor = collection.find()。projection(新しいドキュメント(" _ id "、1))。iterator(); while(cursor.hasNext()){ ドキュメントの結果= cursor.next(); ロングID = result.getLong( "_ id"); // add to combobox } ' –
Veeram