|
1 | 1 | package com.mongodb.mongosh.service
|
2 | 2 |
|
3 |
| -import com.mongodb.CursorType |
4 |
| -import com.mongodb.ReadPreference |
5 |
| -import com.mongodb.TagSet |
| 3 | +import com.mongodb.* |
6 | 4 | import com.mongodb.client.AggregateIterable
|
7 | 5 | import com.mongodb.client.FindIterable
|
8 | 6 | import com.mongodb.client.MongoDatabase
|
9 | 7 | import com.mongodb.client.MongoIterable
|
10 | 8 | import com.mongodb.client.model.CountOptions
|
11 | 9 | import com.mongodb.mongosh.MongoShellConverter
|
| 10 | +import com.mongodb.mongosh.result.DocumentResult |
12 | 11 | import org.bson.Document
|
13 | 12 | import org.graalvm.polyglot.Value
|
14 | 13 |
|
@@ -49,7 +48,7 @@ internal abstract class BaseMongoIterableHelper<T : MongoIterable<*>>(val iterab
|
49 | 48 | open fun tailable(): Unit = throw NotImplementedError("tailable is not supported")
|
50 | 49 | open fun explain(verbosity: String?): Any? = throw NotImplementedError("explain is not supported")
|
51 | 50 | open fun readPrev(v: String, tags: List<TagSet>?): BaseMongoIterableHelper<*> = throw NotImplementedError("readPrev is not supported")
|
52 |
| - open fun readConcern(v: String, tags: List<TagSet>?): BaseMongoIterableHelper<*> = throw NotImplementedError("readConcern is not supported") |
| 51 | + open fun readConcern(v: Value): BaseMongoIterableHelper<*> = throw NotImplementedError("readConcern is not supported") |
53 | 52 |
|
54 | 53 | protected fun set(key: String, value: Any?) {
|
55 | 54 | options[key] = value
|
@@ -95,6 +94,15 @@ internal class AggregateIterableHelper(iterable: AggregateIterable<*>,
|
95 | 94 | return AggregateIterableHelper(newIterable, converter, options, newCreateOptions)
|
96 | 95 | }
|
97 | 96 |
|
| 97 | + override fun readConcern(v: Value): AggregateIterableHelper { |
| 98 | + check(createOptions != null) { "createOptions were not saved" } |
| 99 | + if (!v.hasMembers()) throw IllegalArgumentException("document was expected. Got $v") |
| 100 | + val newDb = readConcernConverter(createOptions.db, (converter.toJava(v) as DocumentResult).value).getOrThrow() |
| 101 | + val newCreateOptions = createOptions.copy(db = newDb) |
| 102 | + val newIterable = aggregate(options, newCreateOptions) |
| 103 | + return AggregateIterableHelper(newIterable, converter, options, newCreateOptions) |
| 104 | + } |
| 105 | + |
98 | 106 | override fun maxTimeMS(v: Long) = set("maxTimeMS", v)
|
99 | 107 | override fun comment(v: String) = set("comment", v)
|
100 | 108 | override fun hint(v: Document) = set("hint", v)
|
@@ -142,6 +150,15 @@ internal class FindIterableHelper(iterable: FindIterable<out Any?>,
|
142 | 150 | return FindIterableHelper(newIterable, converter, options, newCreateOptions)
|
143 | 151 | }
|
144 | 152 |
|
| 153 | + override fun readConcern(v: Value): FindIterableHelper { |
| 154 | + check(createOptions != null) { "createOptions were not saved" } |
| 155 | + if (!v.hasMembers()) throw IllegalArgumentException("document was expected. Got $v") |
| 156 | + val newDb = readConcernConverter(createOptions.db, (converter.toJava(v) as DocumentResult).value).getOrThrow() |
| 157 | + val newCreateOptions = createOptions.copy(db = newDb) |
| 158 | + val newIterable = find(options, newCreateOptions) |
| 159 | + return FindIterableHelper(newIterable, converter, options, newCreateOptions) |
| 160 | + } |
| 161 | + |
145 | 162 | override fun allowPartialResults() = set("allowPartialResults", true)
|
146 | 163 | override fun oplogReplay() = set("oplogReplay", true)
|
147 | 164 | override fun noCursorTimeout() = set("noCursorTimeout", true)
|
|
0 commit comments