ようにするために使用モンゴ-javaのドライバ3.0.4と私たちのコード - のmongo-javaのドライバ3.3.0にこれを変換する問合せMongoのコレクション
DBCollection dbCollection = mongoClient.getDB(databaseName).getCollection(collectionName);
QueryBuilder queryBuilder = new QueryBuilder();
/** queryBuilder.put() for building the query */
DBCursor dbCursor = dbCollection.find(queryBuilder.get());
while(dbCursor.hasNext()) {
DBObject dbObject = dbCursor.next();
// add entries to a list of TDocument type
}
、Iこれで終わった -
MongoCollection<TDocument> collection = database.getCollection(collectionName, TDocument.class); //where TDocument is custom document class of ours
QueryBuilder queryBuilder = new QueryBuilder();
/** queryBuilder.put() for building the query */
FindIterable<TDocument> tDocumentList = collection.find(queryBuilder.get()); //this is not compiling
for (TDocument element : tDocumentList) {
names.add(element.getName()); //addition to some list of TDocument type
}
しかし、ポイントは、私はまだ私が定義したMongoDBのコレクションのfind
操作のソースをコンパイルすることはできませんしています。
ここで何を修正する必要がありますか? mongoを3.3.0+にアップグレードするのに役立つ任意の実装に固執したいと思います。
編集 - マイ(違っlibの名前から下に命名)TDocument
クラスクラスのような単純なPOJOである -
public class TDocType {
private TDocType() {
}
String one;
@NotNull
String name;
String third;
String fourth;
// getter and setter for all the above
}
からフィルタを使用する 変更?それはDBObjectを拡張しますか?そのクラスを投稿に追加します。 – Veeram
@Veeramが追加されたが、なぜそれが必要なのか分からなかった。 – nullpointer
あなたはそれをcast.find(Bson)queryBuilder.get()にキャストすることができます – Veeram