java api を使用する mongodb バージョン 3 では、クエリ中にヒントを与える方法 クエリ結果は、MongoCursor を持つ FindIterable です。 特定のインデックスを使用するためのヒントをどのように与えるべきですか?
古いバージョンでは、ヒント用の API を持つ DBCursor があります。
java api を使用する mongodb バージョン 3 では、クエリ中にヒントを与える方法 クエリ結果は、MongoCursor を持つ FindIterable です。 特定のインデックスを使用するためのヒントをどのように与えるべきですか?
古いバージョンでは、ヒント用の API を持つ DBCursor があります。
修飾子を使用する必要があります:
BasicDBObject index = new BasicDBObject("num", 1);
BasicDBObject hint = new BasicDBObject("$hint", index);
FindIterable<Document> iterable = collection.find().modifiers(hint);
$hint を指定するには、FindIterable.modifiers メソッドを使用する必要があります。
private static void testHint(MongoDatabase db) {
MongoCollection<Document> col = db.getCollection("Stores");
FindIterable<Document> iterable = col.find(new Document("store","storenumbervalue"));
iterable.modifiers(new Document("$hint","index_name"));
MongoCursor curs = iterable.iterator();
while(curs.hasNext()){
System.out.println(curs.next());
}
}
index_name - mongo の実際のインデックス名。