Skip to content
This repository was archived by the owner on Jul 16, 2024. It is now read-only.

Commit 64bce74

Browse files
committed
Added hintString to FindObservable
SCALA-565
1 parent a885ab7 commit 64bce74

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

driver/src/main/scala/org/mongodb/scala/FindObservable.scala

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,20 @@ case class FindObservable[TResult](private val wrapped: FindIterable[TResult]) e
237237
this
238238
}
239239

240+
/**
241+
* Sets the hint to apply.
242+
*
243+
* Note: If [[hint]] is set that will be used instead of any hint string.
244+
*
245+
* @param hint the name of the index which should be used for the operation
246+
* @return this
247+
* @since 2.8
248+
*/
249+
def hintString(hint: String): FindObservable[TResult] = {
250+
wrapped.hintString(hint)
251+
this
252+
}
253+
240254
/**
241255
* Sets the exclusive upper bound for a specific index. A null value means no max is set.
242256
*

driver/src/test/scala/org/mongodb/scala/FindObservableSpec.scala

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ class FindObservableSpec extends FlatSpec with Matchers with MockFactory {
4545
val observable = FindObservable(wrapper)
4646

4747
val filter = Document("a" -> 1)
48+
val hint = Document("a" -> 1)
49+
val hintString = "a_1"
4850
val duration = Duration(1, TimeUnit.SECONDS)
4951
val maxDuration = Duration(10, TimeUnit.SECONDS)
5052
val modifiers = Document("mod" -> 1)
@@ -66,6 +68,8 @@ class FindObservableSpec extends FlatSpec with Matchers with MockFactory {
6668
wrapper.expects(Symbol("collation"))(collation).once()
6769
wrapper.expects(Symbol("cursorType"))(CursorType.NonTailable).once()
6870
wrapper.expects(Symbol("filter"))(filter).once()
71+
wrapper.expects(Symbol("hint"))(hint).once()
72+
wrapper.expects(Symbol("hintString"))(hintString).once()
6973
wrapper.expects(Symbol("getBatchSize"))().once()
7074
wrapper.expects(Symbol("limit"))(1).once()
7175
wrapper.expects(Symbol("maxAwaitTime"))(maxDuration.toMillis, TimeUnit.MILLISECONDS).once()
@@ -87,6 +91,8 @@ class FindObservableSpec extends FlatSpec with Matchers with MockFactory {
8791
observable.collation(collation)
8892
observable.cursorType(CursorType.NonTailable)
8993
observable.filter(filter)
94+
observable.hint(hint)
95+
observable.hintString(hintString)
9096
observable.limit(1)
9197
observable.maxAwaitTime(maxDuration)
9298
observable.maxScan(10L)

0 commit comments

Comments
 (0)