@@ -20,18 +20,18 @@ class TypedMongoCollection[E <: BaseMongoEntity] private(
20
20
docCollection : MongoCollection [BsonDocument ],
21
21
val clientSession : Opt [TypedClientSession ],
22
22
)(implicit
23
- meta : MongoEntityMeta [E ]
23
+ meta : MongoEntityMeta [E ],
24
24
) extends DataTypeDsl [E ] with TypedMongoUtils {
25
25
26
26
def this (
27
27
rawCollection : MongoCollection [_],
28
- clientSession : OptArg [TypedClientSession ] = OptArg .Empty
28
+ clientSession : OptArg [TypedClientSession ] = OptArg .Empty ,
29
29
)(implicit
30
- meta : MongoEntityMeta [E ]
30
+ meta : MongoEntityMeta [E ],
31
31
) = this (
32
32
TypedMongoCollection .mkNativeCollection[E ](rawCollection),
33
33
rawCollection.withDocumentClass(classOf [BsonDocument ]),
34
- clientSession.toOpt
34
+ clientSession.toOpt,
35
35
)
36
36
37
37
type ID = E # IDType
@@ -98,51 +98,51 @@ class TypedMongoCollection[E <: BaseMongoEntity] private(
98
98
99
99
def renameCollection (
100
100
namespace : MongoNamespace ,
101
- setupOptions : RenameCollectionOptions => RenameCollectionOptions = identity
101
+ setupOptions : RenameCollectionOptions => RenameCollectionOptions = identity,
102
102
): Task [Unit ] =
103
103
empty(optionalizeFirstArg(
104
- nativeCollection.renameCollection(sessionOrNull, namespace, setupOptions(new RenameCollectionOptions ))
104
+ nativeCollection.renameCollection(sessionOrNull, namespace, setupOptions(new RenameCollectionOptions )),
105
105
))
106
106
107
107
def countDocuments (
108
108
filter : MongoDocumentFilter [E ] = MongoFilter .empty,
109
- setupOptions : CountOptions => CountOptions = identity
109
+ setupOptions : CountOptions => CountOptions = identity,
110
110
): Task [Long ] =
111
111
single(optionalizeFirstArg(
112
- nativeCollection.countDocuments(sessionOrNull, filter.toBson, setupOptions(new CountOptions ))
112
+ nativeCollection.countDocuments(sessionOrNull, filter.toBson, setupOptions(new CountOptions )),
113
113
)).asInstanceOf [Task [Long ]]
114
114
115
115
def estimatedDocumentCount (
116
- setupOptions : EstimatedDocumentCountOptions => EstimatedDocumentCountOptions = identity
116
+ setupOptions : EstimatedDocumentCountOptions => EstimatedDocumentCountOptions = identity,
117
117
): Task [Long ] =
118
118
single(nativeCollection.estimatedDocumentCount(setupOptions(new EstimatedDocumentCountOptions )))
119
119
.asInstanceOf [Task [Long ]]
120
120
121
121
def exists (
122
122
filter : MongoDocumentFilter [E ],
123
- setupOptions : CountOptions => CountOptions = identity
123
+ setupOptions : CountOptions => CountOptions = identity,
124
124
): Task [Boolean ] =
125
125
countDocuments(filter, options => setupOptions(options).limit(1 )).map(_ > 0 )
126
126
127
127
def findById (
128
128
id : ID ,
129
- setupOptions : FindPublisher [Any ] => FindPublisher [Any ] = identity
129
+ setupOptions : FindPublisher [Any ] => FindPublisher [Any ] = identity,
130
130
): Task [Option [E ]] =
131
131
findOne(IdRef === id, setupOptions = setupOptions)
132
132
133
133
def findOne [T ](
134
134
filter : MongoDocumentFilter [E ] = MongoFilter .empty,
135
135
projection : MongoProjection [E , T ] = SelfRef ,
136
136
sort : MongoDocumentOrder [E ] = MongoDocumentOrder .unspecified,
137
- setupOptions : FindPublisher [Any ] => FindPublisher [Any ] = identity
137
+ setupOptions : FindPublisher [Any ] => FindPublisher [Any ] = identity,
138
138
): Task [Option [T ]] =
139
139
find(filter, projection, sort, o => setupOptions(o).limit(1 )).firstOptionL
140
140
141
141
def find [T ](
142
142
filter : MongoDocumentFilter [E ] = MongoFilter .empty,
143
143
projection : MongoProjection [E , T ] = SelfRef ,
144
144
sort : MongoDocumentOrder [E ] = MongoDocumentOrder .unspecified,
145
- setupOptions : FindPublisher [Any ] => FindPublisher [Any ] = identity
145
+ setupOptions : FindPublisher [Any ] => FindPublisher [Any ] = identity,
146
146
): Observable [T ] = {
147
147
148
148
def setupPublisher [T0 ](publisher : FindPublisher [T0 ]): FindPublisher [T0 ] = {
@@ -171,7 +171,7 @@ class TypedMongoCollection[E <: BaseMongoEntity] private(
171
171
projection : MongoProjection [E , T ] = SelfRef ,
172
172
sort : MongoDocumentOrder [E ] = MongoDocumentOrder .unspecified,
173
173
upsert : Boolean = false , // extracted as separate param because it's very commonly used
174
- setupOptions : FindOneAndUpdateOptions => FindOneAndUpdateOptions = identity
174
+ setupOptions : FindOneAndUpdateOptions => FindOneAndUpdateOptions = identity,
175
175
): Task [Option [T ]] = {
176
176
val filterBson = filter.toFilterBson(Opt .Empty , projection.projectionRefs)
177
177
val options = setupOptions(new FindOneAndUpdateOptions ).sort(sort.toBson).upsert(upsert)
@@ -182,12 +182,12 @@ class TypedMongoCollection[E <: BaseMongoEntity] private(
182
182
projection match {
183
183
case SelfRef =>
184
184
singleOpt(optionalizeFirstArg(
185
- nativeCollection.findOneAndUpdate(sessionOrNull, filterBson, updateBson, options)
185
+ nativeCollection.findOneAndUpdate(sessionOrNull, filterBson, updateBson, options),
186
186
).asInstanceOf [Publisher [T ]])
187
187
case proj =>
188
188
val optionsWithProj = options.projection(proj.toProjectionBson)
189
189
singleOpt(optionalizeFirstArg(
190
- docCollection.findOneAndUpdate(sessionOrNull, filterBson, updateBson, optionsWithProj)
190
+ docCollection.findOneAndUpdate(sessionOrNull, filterBson, updateBson, optionsWithProj),
191
191
)).map(_.map(proj.decodeFrom))
192
192
}
193
193
}
@@ -198,20 +198,20 @@ class TypedMongoCollection[E <: BaseMongoEntity] private(
198
198
projection : MongoProjection [E , T ] = SelfRef ,
199
199
sort : MongoDocumentOrder [E ] = MongoDocumentOrder .unspecified,
200
200
upsert : Boolean = false , // extracted as separate param because it's very commonly used
201
- setupOptions : FindOneAndReplaceOptions => FindOneAndReplaceOptions = identity
201
+ setupOptions : FindOneAndReplaceOptions => FindOneAndReplaceOptions = identity,
202
202
): Task [Option [T ]] = {
203
203
val filterBson = filter.toFilterBson(Opt .Empty , projection.projectionRefs)
204
204
val options = setupOptions(new FindOneAndReplaceOptions ).sort(sort.toBson).upsert(upsert)
205
205
projection match {
206
206
case SelfRef =>
207
207
singleOpt(optionalizeFirstArg(
208
- nativeCollection.findOneAndReplace(sessionOrNull, filterBson, replacement, options)
208
+ nativeCollection.findOneAndReplace(sessionOrNull, filterBson, replacement, options),
209
209
).asInstanceOf [Publisher [T ]])
210
210
case proj =>
211
211
val replaceDoc = format.writeBson(replacement).asDocument
212
212
val optionsWithProj = options.projection(proj.toProjectionBson)
213
213
singleOpt(optionalizeFirstArg(
214
- docCollection.findOneAndReplace(sessionOrNull, filterBson, replaceDoc, optionsWithProj)
214
+ docCollection.findOneAndReplace(sessionOrNull, filterBson, replaceDoc, optionsWithProj),
215
215
)).map(_.map(proj.decodeFrom))
216
216
}
217
217
}
@@ -220,27 +220,27 @@ class TypedMongoCollection[E <: BaseMongoEntity] private(
220
220
filter : MongoDocumentFilter [E ],
221
221
projection : MongoProjection [E , T ] = SelfRef ,
222
222
sort : MongoDocumentOrder [E ] = MongoDocumentOrder .unspecified,
223
- setupOptions : FindOneAndDeleteOptions => FindOneAndDeleteOptions = identity
223
+ setupOptions : FindOneAndDeleteOptions => FindOneAndDeleteOptions = identity,
224
224
): Task [Option [T ]] = {
225
225
val filterBson = filter.toFilterBson(Opt .Empty , projection.projectionRefs)
226
226
val options = setupOptions(new FindOneAndDeleteOptions ).sort(sort.toBson)
227
227
projection match {
228
228
case SelfRef =>
229
229
singleOpt(optionalizeFirstArg(
230
- nativeCollection.findOneAndDelete(sessionOrNull, filterBson, options)
230
+ nativeCollection.findOneAndDelete(sessionOrNull, filterBson, options),
231
231
).asInstanceOf [Publisher [T ]])
232
232
case proj =>
233
233
val optionsWithProj = options.projection(proj.toProjectionBson)
234
234
singleOpt(optionalizeFirstArg(
235
- docCollection.findOneAndDelete(sessionOrNull, filterBson, optionsWithProj))
235
+ docCollection.findOneAndDelete(sessionOrNull, filterBson, optionsWithProj)),
236
236
).map(_.map(proj.decodeFrom))
237
237
}
238
238
}
239
239
240
240
def distinct [T ](
241
241
property : MongoPropertyRef [E , T ],
242
242
filter : MongoDocumentFilter [E ] = MongoFilter .empty,
243
- setupOptions : DistinctPublisher [Any ] => DistinctPublisher [Any ] = identity
243
+ setupOptions : DistinctPublisher [Any ] => DistinctPublisher [Any ] = identity,
244
244
): Observable [T ] = {
245
245
246
246
val publisher =
@@ -255,104 +255,104 @@ class TypedMongoCollection[E <: BaseMongoEntity] private(
255
255
256
256
def insertOne (
257
257
value : E ,
258
- setupOptions : InsertOneOptions => InsertOneOptions = identity
258
+ setupOptions : InsertOneOptions => InsertOneOptions = identity,
259
259
): Task [InsertOneResult ] =
260
260
single(optionalizeFirstArg(
261
- nativeCollection.insertOne(sessionOrNull, value, setupOptions(new InsertOneOptions ))
261
+ nativeCollection.insertOne(sessionOrNull, value, setupOptions(new InsertOneOptions )),
262
262
))
263
263
264
264
def insertMany (
265
265
values : Seq [E ],
266
- setupOptions : InsertManyOptions => InsertManyOptions = identity
266
+ setupOptions : InsertManyOptions => InsertManyOptions = identity,
267
267
): Task [InsertManyResult ] =
268
268
single(optionalizeFirstArg(
269
- nativeCollection.insertMany(sessionOrNull, values.asJava, setupOptions(new InsertManyOptions ))
269
+ nativeCollection.insertMany(sessionOrNull, values.asJava, setupOptions(new InsertManyOptions )),
270
270
))
271
271
272
272
def deleteOne (
273
273
filter : MongoDocumentFilter [E ],
274
- setupOptions : DeleteOptions => DeleteOptions = identity
274
+ setupOptions : DeleteOptions => DeleteOptions = identity,
275
275
): Task [DeleteResult ] =
276
276
single(optionalizeFirstArg(
277
- nativeCollection.deleteOne(sessionOrNull, filter.toBson, setupOptions(new DeleteOptions ))
277
+ nativeCollection.deleteOne(sessionOrNull, filter.toBson, setupOptions(new DeleteOptions )),
278
278
))
279
279
280
280
def deleteMany (
281
281
filter : MongoDocumentFilter [E ],
282
- setupOptions : DeleteOptions => DeleteOptions = identity
282
+ setupOptions : DeleteOptions => DeleteOptions = identity,
283
283
): Task [DeleteResult ] =
284
284
single(optionalizeFirstArg(
285
- nativeCollection.deleteMany(sessionOrNull, filter.toBson, setupOptions(new DeleteOptions ))
285
+ nativeCollection.deleteMany(sessionOrNull, filter.toBson, setupOptions(new DeleteOptions )),
286
286
))
287
287
288
288
def updateOne (
289
289
filter : MongoDocumentFilter [E ],
290
290
update : MongoDocumentUpdate [E ],
291
291
upsert : Boolean = false , // extracted as separate param because it's very commonly used
292
- setupOptions : UpdateOptions => UpdateOptions = identity
292
+ setupOptions : UpdateOptions => UpdateOptions = identity,
293
293
): Task [UpdateResult ] = {
294
294
val options = setupOptions(new UpdateOptions ).upsert(upsert)
295
295
val (updateBson, arrayFilters) = update.toBsonAndArrayFilters
296
296
if (! arrayFilters.isEmpty) {
297
297
options.arrayFilters(arrayFilters)
298
298
}
299
299
single(optionalizeFirstArg(
300
- nativeCollection.updateOne(sessionOrNull, filter.toBson, updateBson, options)
300
+ nativeCollection.updateOne(sessionOrNull, filter.toBson, updateBson, options),
301
301
))
302
302
}
303
303
304
304
def updateMany (
305
305
filter : MongoDocumentFilter [E ],
306
306
update : MongoDocumentUpdate [E ],
307
307
upsert : Boolean = false , // extracted as separate param because it's very commonly used
308
- setupOptions : UpdateOptions => UpdateOptions = identity
308
+ setupOptions : UpdateOptions => UpdateOptions = identity,
309
309
): Task [UpdateResult ] = {
310
310
val options = setupOptions(new UpdateOptions ).upsert(upsert)
311
311
val (updateBson, arrayFilters) = update.toBsonAndArrayFilters
312
312
if (! arrayFilters.isEmpty) {
313
313
options.arrayFilters(arrayFilters)
314
314
}
315
315
single(optionalizeFirstArg(
316
- nativeCollection.updateMany(sessionOrNull, filter.toBson, updateBson, options)
316
+ nativeCollection.updateMany(sessionOrNull, filter.toBson, updateBson, options),
317
317
))
318
318
}
319
319
320
320
def replaceOne (
321
321
filter : MongoDocumentFilter [E ],
322
322
replacement : E ,
323
323
upsert : Boolean = false , // extracted as separate param because it's very commonly used
324
- setupOptions : ReplaceOptions => ReplaceOptions = identity
324
+ setupOptions : ReplaceOptions => ReplaceOptions = identity,
325
325
): Task [UpdateResult ] = {
326
326
val options = setupOptions(new ReplaceOptions ).upsert(upsert)
327
327
single(optionalizeFirstArg(
328
- nativeCollection.replaceOne(sessionOrNull, filter.toBson, replacement, options)
328
+ nativeCollection.replaceOne(sessionOrNull, filter.toBson, replacement, options),
329
329
))
330
330
}
331
331
332
332
def bulkWrite (
333
333
writes : Seq [MongoWrite [E ]],
334
- setupOptions : BulkWriteOptions => BulkWriteOptions = identity
334
+ setupOptions : BulkWriteOptions => BulkWriteOptions = identity,
335
335
): Task [BulkWriteResult ] = {
336
336
val requests = writes.iterator.map(_.toWriteModel).to(JList )
337
337
single(optionalizeFirstArg(
338
- nativeCollection.bulkWrite(sessionOrNull, requests, setupOptions(new BulkWriteOptions ))
338
+ nativeCollection.bulkWrite(sessionOrNull, requests, setupOptions(new BulkWriteOptions )),
339
339
))
340
340
}
341
341
342
342
def createIndex (index : MongoIndex [E ]): Task [String ] =
343
343
single(optionalizeFirstArg(
344
- nativeCollection.createIndex(sessionOrNull, index.toBson, index.setupOptions(new IndexOptions ))
344
+ nativeCollection.createIndex(sessionOrNull, index.toBson, index.setupOptions(new IndexOptions )),
345
345
))
346
346
347
347
def createIndexes (
348
348
indexes : Seq [MongoIndex [E ]],
349
- setupOptions : CreateIndexOptions => CreateIndexOptions = identity
349
+ setupOptions : CreateIndexOptions => CreateIndexOptions = identity,
350
350
): Task [String ] = {
351
351
val indexModels = indexes.iterator
352
352
.map(index => new IndexModel (index.toBson, index.setupOptions(new IndexOptions )))
353
353
.to(JList )
354
354
single(optionalizeFirstArg(
355
- nativeCollection.createIndexes(sessionOrNull, indexModels, setupOptions(new CreateIndexOptions ))
355
+ nativeCollection.createIndexes(sessionOrNull, indexModels, setupOptions(new CreateIndexOptions )),
356
356
))
357
357
}
358
358
@@ -365,9 +365,9 @@ class TypedMongoCollection[E <: BaseMongoEntity] private(
365
365
366
366
object TypedMongoCollection {
367
367
private def mkNativeCollection [E <: BaseMongoEntity : MongoEntityMeta ](
368
- rawCollection : MongoCollection [_]
368
+ rawCollection : MongoCollection [_],
369
369
)(implicit
370
- meta : MongoEntityMeta [E ]
370
+ meta : MongoEntityMeta [E ],
371
371
): MongoCollection [E ] = {
372
372
import meta .format ._
373
373
val codecRegistry : CodecRegistry = GenCodecRegistry .create[E ](rawCollection.getCodecRegistry)
0 commit comments