File tree Expand file tree Collapse file tree 2 files changed +26
-23
lines changed Expand file tree Collapse file tree 2 files changed +26
-23
lines changed Original file line number Diff line number Diff line change @@ -112,20 +112,25 @@ and :ref:`kotlin-sync-db-coll-create-collection` examples:
112
112
.. output::
113
113
114
114
{
115
- "name": "october2024",
116
- "type": "timeseries",
117
- "options": {
118
- "timeseries": {
119
- "timeField": "temperature",
120
- "granularity": "seconds",
121
- "bucketMaxSpanSeconds": 3600
122
- }
123
- },
124
- "info": {
125
- "readOnly": false
126
- }
127
- }
128
- ...
115
+ "name": "example_collection",
116
+ "type": "collection",
117
+ "options": {},
118
+ "info": {
119
+ "readOnly": false,
120
+ ...
121
+ },
122
+ "idIndex": { ... }
123
+ }
124
+ {
125
+ "name": "test_collection",
126
+ "type": "collection",
127
+ "options": {},
128
+ "info": {
129
+ "readOnly": false,
130
+ ...
131
+ },
132
+ "idIndex": { ... }
133
+ }
129
134
130
135
Delete a Collection
131
136
-------------------
Original file line number Diff line number Diff line change 1
1
import com.mongodb.ConnectionString
2
2
import com.mongodb.MongoClientSettings
3
- import com.mongodb.ReadConcern
4
- import com.mongodb.ReadPreference
5
- import com.mongodb.WriteConcern
6
- import com.mongodb.client.MongoClient
7
- import com.mongodb.client.MongoClients
8
- import com.mongodb.client.MongoCollection
9
- import com.mongodb.client.MongoDatabase
3
+ import com.mongodb.kotlin.client.MongoClient
10
4
import org.bson.Document
5
+ import org.bson.json.JsonWriterSettings
11
6
12
7
fun main () {
13
8
val uri = " <connection string URI>"
@@ -36,8 +31,11 @@ fun main() {
36
31
37
32
// Lists the collections in the "test_database" database
38
33
// start-find-collections
39
- for (collectionInfo in client.getDatabase(" test_database" ).listCollections()) {
40
- println (collectionInfo.toJson())
34
+ val results = db.listCollections()
35
+ val jsonSettings = JsonWriterSettings .builder().indent(true ).build()
36
+
37
+ results.forEach { result ->
38
+ println (result.toJson(jsonSettings))
41
39
}
42
40
// end-find-collections
43
41
You can’t perform that action at this time.
0 commit comments