forked from konrad-kaminski/spring-kotlin-coroutine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CoroutineMongoOperations.kt
1720 lines (1589 loc) · 77 KB
/
CoroutineMongoOperations.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Copyright 2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.data.mongodb.core
import com.mongodb.ReadPreference
import com.mongodb.client.result.DeleteResult
import com.mongodb.client.result.UpdateResult
import com.mongodb.coroutines.client.CoroutineMongoCollection
import kotlinx.coroutines.channels.ReceiveChannel
import org.bson.Document
import org.reactivestreams.Subscription
import org.springframework.data.geo.GeoResult
import org.springframework.data.mongodb.core.aggregation.Aggregation
import org.springframework.data.mongodb.core.aggregation.AggregationOptions
import org.springframework.data.mongodb.core.aggregation.TypedAggregation
import org.springframework.data.mongodb.core.convert.MappingMongoConverter
import org.springframework.data.mongodb.core.convert.MongoConverter
import org.springframework.data.mongodb.core.index.CoroutineIndexOperations
import org.springframework.data.mongodb.core.query.BasicQuery
import org.springframework.data.mongodb.core.query.Criteria
import org.springframework.data.mongodb.core.query.NearQuery
import org.springframework.data.mongodb.core.query.Query
import org.springframework.data.mongodb.core.query.Update
interface CoroutineMongoOperations {
/**
* Returns the coroutine operations that can be performed on indexes
*
* @return index operations on the named collection
*/
fun indexOps(collectionName: String): CoroutineIndexOperations
/**
* Returns the coroutine operations that can be performed on indexes
*
* @return index operations on the named collection associated with the given entity class
*/
fun indexOps(entityClass: Class<*>): CoroutineIndexOperations
/**
* Execute the a MongoDB command expressed as a JSON string. This will call the method JSON.parse that is part of the
* MongoDB driver to convert the JSON string to a DBObject. Any errors that result from executing this command will be
* converted into Spring's DAO exception hierarchy.
*
* @param jsonCommand a MongoDB command expressed as a JSON string.
* @return a result object returned by the action
*/
suspend fun executeCommand(jsonCommand: String): Document?
/**
* Execute a MongoDB command. Any errors that result from executing this command will be converted into Spring's DAO
* exception hierarchy.
*
* @param command a MongoDB command
* @return a result object returned by the action
*/
suspend fun executeCommand(command: Document): Document?
/**
* Execute a MongoDB command. Any errors that result from executing this command will be converted into Spring's data
* access exception hierarchy.
*
* @param command a MongoDB command, must not be null.
* @param readPreference read preferences to use, can be null.
* @return a result object returned by the action
*/
suspend fun executeCommand(command: Document, readPreference: ReadPreference): Document?
/**
* Executes a [CoroutineDatabaseCallback] translating any exceptions as necessary.
*
*
* Allows for returning a result object, that is a domain object or a collection of domain objects.
*
* @param <T> return type
* @param action callback object that specifies the MongoDB actions to perform on the passed in DB instance.
* @return a result object returned by the action
</T> */
suspend fun <T> execute(action: CoroutineDatabaseCallback<T>): List<T>
/**
* Executes the given [CoroutineCollectionCallback] on the entity collection of the specified class.
*
*
* Allows for returning a result object, that is a domain object or a collection of domain objects.
*
* @param entityClass class that determines the collection to use
* @param <T> return type
* @param action callback object that specifies the MongoDB action
* @return a result object returned by the action or <tt>null</tt>
</T> */
suspend fun <T> execute(entityClass: Class<*>, action: CoroutineCollectionCallback<T>): List<T>
/**
* Executes the given [CoroutineCollectionCallback] on the collection of the given name.
*
*
* Allows for returning a result object, that is a domain object or a collection of domain objects.
*
* @param <T> return type
* @param collectionName the name of the collection that specifies which DBCollection instance will be passed into
* @param action callback object that specifies the MongoDB action the callback action.
* @return a result object returned by the action or <tt>null</tt>
</T> */
suspend fun <T> execute(collectionName: String, action: CoroutineCollectionCallback<T>): List<T>
/**
* Create an uncapped collection with a name based on the provided entity class.
*
* @param entityClass class that determines the collection to create
* @return the created collection
*/
suspend fun <T> createCollection(entityClass: Class<T>): CoroutineMongoCollection<Document>
/**
* Create a collection with a name based on the provided entity class using the options.
*
* @param entityClass class that determines the collection to create
* @param collectionOptions options to use when creating the collection.
* @return the created collection
*/
suspend fun <T> createCollection(entityClass: Class<T>, collectionOptions: CollectionOptions): CoroutineMongoCollection<Document>
/**
* Create an uncapped collection with the provided name.
*
* @param collectionName name of the collection
* @return the created collection
*/
suspend fun createCollection(collectionName: String): CoroutineMongoCollection<Document>
/**
* Create a collection with the provided name and options.
*
* @param collectionName name of the collection
* @param collectionOptions options to use when creating the collection.
* @return the created collection
*/
suspend fun createCollection(collectionName: String, collectionOptions: CollectionOptions): CoroutineMongoCollection<Document>
/**
* A set of collection names.
*
* @return Flux of collection names
*/
suspend fun getCollectionNames(): List<String>
/**
* Get a collection by name, creating it if it doesn't exist.
*
*
* Translate any exceptions as necessary.
*
* @param collectionName name of the collection
* @return an existing collection or a newly created one.
*/
fun getCollection(collectionName: String): CoroutineMongoCollection<Document>
/**
* Check to see if a collection with a name indicated by the entity class exists.
*
*
* Translate any exceptions as necessary.
*
* @param entityClass class that determines the name of the collection
* @return true if a collection with the given name is found, false otherwise.
*/
suspend fun <T> collectionExists(entityClass: Class<T>): Boolean
/**
* Check to see if a collection with a given name exists.
*
*
* Translate any exceptions as necessary.
*
* @param collectionName name of the collection
* @return true if a collection with the given name is found, false otherwise.
*/
suspend fun collectionExists(collectionName: String): Boolean
/**
* Drop the collection with the name indicated by the entity class.
*
*
* Translate any exceptions as necessary.
*
* @param entityClass class that determines the collection to drop/delete.
*/
suspend fun <T> dropCollection(entityClass: Class<T>)
/**
* Drop the collection with the given name.
*
*
* Translate any exceptions as necessary.
*
* @param collectionName name of the collection to drop/delete.
*/
suspend fun dropCollection(collectionName: String)
/**
* Query for a [List] of objects of type T from the collection used by the entity class.
*
*
* The object is converted from the MongoDB native representation using an instance of {@see MongoConverter}. Unless
* configured otherwise, an instance of [MappingMongoConverter] will be used.
*
*
* If your collection does not contain a homogeneous collection of types, this operation will not be an efficient way
* to map objects since the test for class type is done in the client and not on the server.
*
* @param entityClass the parametrized type of the returned [List].
* @return the converted collection
*/
suspend fun <T> findAll(entityClass: Class<T>): List<T>
/**
* Query for a [List] of objects of type T from the specified collection.
*
*
* The object is converted from the MongoDB native representation using an instance of {@see MongoConverter}. Unless
* configured otherwise, an instance of [MappingMongoConverter] will be used.
*
*
* If your collection does not contain a homogeneous collection of types, this operation will not be an efficient way
* to map objects since the test for class type is done in the client and not on the server.
*
* @param entityClass the parametrized type of the returned [List].
* @param collectionName name of the collection to retrieve the objects from
* @return the converted collection
*/
suspend fun <T> findAll(entityClass: Class<T>, collectionName: String): List<T>
/**
* Map the results of an ad-hoc query on the collection for the entity class to a single instance of an object of the
* specified type.
*
*
* The object is converted from the MongoDB native representation using an instance of {@see MongoConverter}. Unless
* configured otherwise, an instance of [MappingMongoConverter] will be used.
*
*
* The query is specified as a [Query] which can be created either using the [BasicQuery] or the more
* feature rich [Query].
*
* @param query the query class that specifies the criteria used to find a record and also an optional fields
* specification
* @param entityClass the parametrized type of the returned object.
* @return the converted object
*/
suspend fun <T> findOne(query: Query, entityClass: Class<T>): T?
/**
* Map the results of an ad-hoc query on the specified collection to a single instance of an object of the specified
* type.
*
*
* The object is converted from the MongoDB native representation using an instance of {@see MongoConverter}. Unless
* configured otherwise, an instance of [MappingMongoConverter] will be used.
*
*
* The query is specified as a [Query] which can be created either using the [BasicQuery] or the more
* feature rich [Query].
*
* @param query the query class that specifies the criteria used to find a record and also an optional fields
* specification
* @param entityClass the parametrized type of the returned object.
* @param collectionName name of the collection to retrieve the objects from
* @return the converted object
*/
suspend fun <T> findOne(query: Query, entityClass: Class<T>, collectionName: String): T?
/**
* Determine result of given [Query] contains at least one element. <br></br>
* **NOTE:** Any additional support for query/field mapping, etc. is not available due to the lack of
* domain type information. Use [.exists] to get full type specific support.
*
* @param query the [Query] class that specifies the criteria used to find a record.
* @param collectionName name of the collection to check for objects.
* @return
*/
suspend fun exists(query: Query, collectionName: String): Boolean
/**
* Determine result of given [Query] contains at least one element.
*
* @param query the [Query] class that specifies the criteria used to find a record.
* @param entityClass the parametrized type.
* @return
*/
suspend fun exists(query: Query, entityClass: Class<*>): Boolean
/**
* Determine result of given [Query] contains at least one element.
*
* @param query the [Query] class that specifies the criteria used to find a record.
* @param entityClass the parametrized type.
* @param collectionName name of the collection to check for objects.
* @return
*/
suspend fun exists(query: Query, entityClass: Class<*>, collectionName: String): Boolean
/**
* Map the results of an ad-hoc query on the collection for the entity class to a [ReceiveChannel] of the specified type.
*
*
* The object is converted from the MongoDB native representation using an instance of {@see MongoConverter}. Unless
* configured otherwise, an instance of [MappingMongoConverter] will be used.
*
*
* The query is specified as a [Query] which can be created either using the [BasicQuery] or the more
* feature rich [Query].
*
* @param query the query class that specifies the criteria used to find a record and also an optional fields
* specification
* @param entityClass the parametrized type of the returned [ReceiveChannel].
* @return the [ReceiveChannel] of converted objects
*/
suspend fun <T> find(query: Query, entityClass: Class<T>): List<T>
/**
* Map the results of an ad-hoc query on the specified collection to a [ReceiveChannel] of the specified type.
*
*
* The object is converted from the MongoDB native representation using an instance of {@see MongoConverter}. Unless
* configured otherwise, an instance of [MappingMongoConverter] will be used.
*
*
* The query is specified as a [Query] which can be created either using the [BasicQuery] or the more
* feature rich [Query].
*
* @param query the query class that specifies the criteria used to find a record and also an optional fields
* specification
* @param entityClass the parametrized type of the returned [ReceiveChannel].
* @param collectionName name of the collection to retrieve the objects from
* @return the [ReceiveChannel] of converted objects
*/
suspend fun <T> find(query: Query, entityClass: Class<T>, collectionName: String): List<T>
/**
* Returns a document with the given id mapped onto the given class. The collection the query is ran against will be
* derived from the given target class as well.
*
* @param <T>
* @param id the id of the document to return.
* @param entityClass the type the document shall be converted into.
* @return the document with the given id mapped onto the given target class.
</T> */
suspend fun <T> findById(id: Any, entityClass: Class<T>): T?
/**
* Returns the document with the given id from the given collection mapped onto the given target class.
*
* @param id the id of the document to return
* @param entityClass the type to convert the document to
* @param collectionName the collection to query for the document
* @param <T>
* @return
</T> */
suspend fun <T> findById(id: Any, entityClass: Class<T>, collectionName: String): T?
/**
* Execute an aggregation operation.
*
*
* The raw results will be mapped to the given entity class.
*
*
* Aggregation streaming cannot be used with [aggregation explain][AggregationOptions.isExplain] nor with
* [AggregationOptions.getCursorBatchSize]. Enabling explanation mode or setting batch size cause
* [IllegalArgumentException].
*
* @param aggregation The [TypedAggregation] specification holding the aggregation operations. Must not be
* null.
* @param collectionName The name of the input collection to use for the aggregation. Must not be null.
* @param outputType The parametrized type of the returned [ReceiveChannel]. Must not be null.
* @return The results of the aggregation operation.
* @throws IllegalArgumentException if `aggregation`, `collectionName` or `outputType` is
* null.
*/
suspend fun <O> aggregate(aggregation: TypedAggregation<*>, collectionName: String, outputType: Class<O>): List<O>
/**
* Execute an aggregation operation.
*
*
* The raw results will be mapped to the given entity class and are returned as stream. The name of the
* inputCollection is derived from the [aggregation input type][TypedAggregation.getInputType].
*
*
* Aggregation streaming cannot be used with [aggregation explain][AggregationOptions.isExplain] nor with
* [AggregationOptions.getCursorBatchSize]. Enabling explanation mode or setting batch size cause
* [IllegalArgumentException].
*
* @param aggregation The [TypedAggregation] specification holding the aggregation operations. Must not be
* null.
* @param outputType The parametrized type of the returned [ReceiveChannel]. Must not be null.
* @return The results of the aggregation operation.
* @throws IllegalArgumentException if `aggregation` or `outputType` is null.
*/
suspend fun <O> aggregate(aggregation: TypedAggregation<*>, outputType: Class<O>): List<O>
/**
* Execute an aggregation operation.
*
*
* The raw results will be mapped to the given `ouputType`. The name of the inputCollection is derived from the
* `inputType`.
*
*
* Aggregation streaming cannot be used with [aggregation explain][AggregationOptions.isExplain] nor with
* [AggregationOptions.getCursorBatchSize]. Enabling explanation mode or setting batch size cause
* [IllegalArgumentException].
*
* @param aggregation The [Aggregation] specification holding the aggregation operations. Must not be
* null.
* @param inputType the inputType where the aggregation operation will read from. Must not be null.
* @param outputType The parametrized type of the returned [ReceiveChannel]. Must not be null.
* @return The results of the aggregation operation.
* @throws IllegalArgumentException if `aggregation`, `inputType` or `outputType` is
* null.
*/
suspend fun <O> aggregate(aggregation: Aggregation, inputType: Class<*>, outputType: Class<O>): List<O>
/**
* Execute an aggregation operation.
*
*
* The raw results will be mapped to the given entity class.
*
*
* Aggregation streaming cannot be used with [aggregation explain][AggregationOptions.isExplain] nor with
* [AggregationOptions.getCursorBatchSize]. Enabling explanation mode or setting batch size cause
* [IllegalArgumentException].
*
* @param aggregation The [Aggregation] specification holding the aggregation operations. Must not be
* null.
* @param collectionName the collection where the aggregation operation will read from. Must not be null or
* empty.
* @param outputType The parametrized type of the returned [ReceiveChannel]. Must not be null.
* @return The results of the aggregation operation.
* @throws IllegalArgumentException if `aggregation`, `collectionName` or `outputType` is
* null.
*/
suspend fun <O> aggregate(aggregation: Aggregation, collectionName: String, outputType: Class<O>): List<O>
/**
* Returns [ReceiveChannel] of [GeoResult] for all entities matching the given [NearQuery]. Will consider
* entity mapping information to determine the collection the query is ran against. Note, that MongoDB limits the
* number of results by default. Make sure to add an explicit limit to the [NearQuery] if you expect a
* particular number of results.
*
* @param near must not be null.
* @param entityClass must not be null.
* @return
*/
suspend fun <T> geoNear(near: NearQuery, entityClass: Class<T>): List<GeoResult<T>>
/**
* Returns [ReceiveChannel] of [GeoResult] for all entities matching the given [NearQuery]. Note, that MongoDB
* limits the number of results by default. Make sure to add an explicit limit to the [NearQuery] if you expect
* a particular number of results.
*
* @param near must not be null.
* @param entityClass must not be null.
* @param collectionName the collection to trigger the query against. If no collection name is given the entity class
* will be inspected.
* @return
*/
suspend fun <T> geoNear(near: NearQuery, entityClass: Class<T>, collectionName: String): List<GeoResult<T>>
/**
* Triggers [findAndModify <a></a>
* to apply provided [Update] on documents matching [Criteria] of given [Query].
*
* @param query the [Query] class that specifies the [Criteria] used to find a record and also an optional
* fields specification.
* @param update the [Update] to apply on matching documents.
* @param entityClass the parametrized type.
* @return
](https://docs.mongodb.org/manual/reference/method/db.collection.findAndModify/) */
suspend fun <T> findAndModify(query: Query, update: Update, entityClass: Class<T>): T?
/**
* Triggers [findAndModify <a></a>
* to apply provided [Update] on documents matching [Criteria] of given [Query].
*
* @param query the [Query] class that specifies the [Criteria] used to find a record and also an optional
* fields specification.
* @param update the [Update] to apply on matching documents.
* @param entityClass the parametrized type.
* @param collectionName the collection to query.
* @return
](https://docs.mongodb.org/manual/reference/method/db.collection.findAndModify/) */
suspend fun <T> findAndModify(query: Query, update: Update, entityClass: Class<T>, collectionName: String): T?
/**
* Triggers [findAndModify <a></a>
* to apply provided [Update] on documents matching [Criteria] of given [Query] taking
* [FindAndModifyOptions] into account.
*
* @param query the [Query] class that specifies the [Criteria] used to find a record and also an optional
* fields specification.
* @param update the [Update] to apply on matching documents.
* @param options the [FindAndModifyOptions] holding additional information.
* @param entityClass the parametrized type.
* @return
](https://docs.mongodb.org/manual/reference/method/db.collection.findAndModify/) */
suspend fun <T> findAndModify(query: Query, update: Update, options: FindAndModifyOptions, entityClass: Class<T>): T?
/**
* Triggers [findAndModify <a></a>
* to apply provided [Update] on documents matching [Criteria] of given [Query] taking
* [FindAndModifyOptions] into account.
*
* @param query the [Query] class that specifies the [Criteria] used to find a record and also an optional
* fields specification.
* @param update the [Update] to apply on matching documents.
* @param options the [FindAndModifyOptions] holding additional information.
* @param entityClass the parametrized type.
* @param collectionName the collection to query.
* @return
](https://docs.mongodb.org/manual/reference/method/db.collection.findAndModify/) */
suspend fun <T> findAndModify(query: Query, update: Update, options: FindAndModifyOptions, entityClass: Class<T>,
collectionName: String): T?
/**
* Map the results of an ad-hoc query on the collection for the entity type to a single instance of an object of the
* specified type. The first document that matches the query is returned and also removed from the collection in the
* database.
*
*
* The object is converted from the MongoDB native representation using an instance of {@see MongoConverter}.
*
*
* The query is specified as a [Query] which can be created either using the [BasicQuery] or the more
* feature rich [Query].
*
* @param query the query class that specifies the criteria used to find a record and also an optional fields
* specification
* @param entityClass the parametrized type of the returned object.
* @return the converted object
*/
suspend fun <T> findAndRemove(query: Query, entityClass: Class<T>): T?
/**
* Map the results of an ad-hoc query on the specified collection to a single instance of an object of the specified
* type. The first document that matches the query is returned and also removed from the collection in the database.
*
*
* The object is converted from the MongoDB native representation using an instance of {@see MongoConverter}. Unless
* configured otherwise, an instance of [MappingMongoConverter] will be used.
*
*
* The query is specified as a [Query] which can be created either using the [BasicQuery] or the more
* feature rich [Query].
*
* @param query the query class that specifies the criteria used to find a record and also an optional fields
* specification
* @param entityClass the parametrized type of the returned object.
* @param collectionName name of the collection to retrieve the objects from.
* @return the converted object
*/
suspend fun <T> findAndRemove(query: Query, entityClass: Class<T>, collectionName: String): T?
/**
* Returns the number of documents for the given [Query] by querying the collection of the given entity class.
*
* @param query
* @param entityClass must not be null.
* @return
*/
suspend fun count(query: Query, entityClass: Class<*>): Long
/**
* Returns the number of documents for the given [Query] querying the given collection. The given [Query]
* must solely consist of document field references as we lack type information to map potential property references
* onto document fields. Use [.count] to get full type specific support.
*
* @param query
* @param collectionName must not be null or empty.
* @return
* @see .count
*/
suspend fun count(query: Query, collectionName: String): Long
/**
* Returns the number of documents for the given [Query] by querying the given collection using the given entity
* class to map the given [Query].
*
* @param query
* @param entityClass must not be null.
* @param collectionName must not be null or empty.
* @return
*/
suspend fun count(query: Query, entityClass: Class<*>, collectionName: String): Long
/**
* Insert the object into the collection for the entity type of the object to save.
*
*
* The object is converted to the MongoDB native representation using an instance of {@see MongoConverter}.
*
*
* If you object has an "Id' property, it will be set with the generated Id from MongoDB. If your Id property is a
* String then MongoDB ObjectId will be used to populate that string. Otherwise, the conversion from ObjectId to your
* property type will be handled by Spring's BeanWrapper class that leverages Type Conversion API. See
* [
* Spring's Type Conversion"](http://docs.spring.io/spring/docs/current/spring-framework-reference/html/validation.html#core-convert) for more details.
*
*
*
*
* Insert is used to initially store the object into the database. To update an existing object use the save method.
*
* @param objectToSave the object to store in the collection.
* @return
*/
suspend fun <T> insert(objectToSave: T): T?
/**
* Insert the object into the specified collection.
*
*
* The object is converted to the MongoDB native representation using an instance of {@see MongoConverter}. Unless
* configured otherwise, an instance of [MappingMongoConverter] will be used.
*
*
* Insert is used to initially store the object into the database. To update an existing object use the save method.
*
* @param objectToSave the object to store in the collection
* @param collectionName name of the collection to store the object in
* @return
*/
suspend fun <T> insert(objectToSave: T, collectionName: String): T?
/**
* Insert a Collection of objects into a collection in a single batch write to the database.
*
* @param batchToSave the batch of objects to save.
* @param entityClass class that determines the collection to use
* @return
*/
suspend fun <T> insert(batchToSave: Collection<T>, entityClass: Class<*>): List<T>
/**
* Insert a batch of objects into the specified collection in a single batch write to the database.
*
* @param batchToSave the list of objects to save.
* @param collectionName name of the collection to store the object in
* @return
*/
suspend fun <T> insert(batchToSave: Collection<T>, collectionName: String): List<T>
/**
* Insert a mixed Collection of objects into a database collection determining the collection name to use based on the
* class.
*
* @param objectsToSave the list of objects to save.
* @return
*/
suspend fun <T> insertAll(objectsToSave: Collection<T>): List<T>
/**
* Insert the object into the collection for the entity type of the object to save.
*
*
* The object is converted to the MongoDB native representation using an instance of {@see MongoConverter}.
*
*
* If you object has an "Id' property, it will be set with the generated Id from MongoDB. If your Id property is a
* String then MongoDB ObjectId will be used to populate that string. Otherwise, the conversion from ObjectId to your
* property type will be handled by Spring's BeanWrapper class that leverages Type Conversion API. See
* [
* Spring's Type Conversion"](http://docs.spring.io/spring/docs/current/spring-framework-reference/html/validation.html#core-convert) for more details.
*
*
*
*
* Insert is used to initially store the object into the database. To update an existing object use the save method.
*
* @param objectToSave the object to store in the collection.
* @return
*/
suspend fun <T> insert(objectToSave: suspend () -> T?): T?
/**
* Insert a Collection of objects into a collection in a single batch write to the database.
*
* @param batchToSave the publisher which provides objects to save.
* @param entityClass class that determines the collection to use
* @return
*/
suspend fun <T> insertAll(batchToSave: suspend () -> Collection<T>, entityClass: Class<*>): List<T>
/**
* Insert objects into the specified collection in a single batch write to the database.
*
* @param batchToSave the publisher which provides objects to save.
* @param collectionName name of the collection to store the object in
* @return
*/
suspend fun <T> insertAll(batchToSave: suspend () -> Collection<T>, collectionName: String): List<T>
/**
* Insert a mixed Collection of objects into a database collection determining the collection name to use based on the
* class.
*
* @param objectsToSave the publisher which provides objects to save.
* @return
*/
suspend fun <T> insertAll(objectsToSave: suspend () -> Collection<T>): List<T>
/**
* Save the object to the collection for the entity type of the object to save. This will perform an insert if the
* object is not already present, that is an 'upsert'.
*
*
* The object is converted to the MongoDB native representation using an instance of {@see MongoConverter}. Unless
* configured otherwise, an instance of [MappingMongoConverter] will be used.
*
*
* If you object has an "Id' property, it will be set with the generated Id from MongoDB. If your Id property is a
* String then MongoDB ObjectId will be used to populate that string. Otherwise, the conversion from ObjectId to your
* property type will be handled by Spring's BeanWrapper class that leverages Type Conversion API. See
* [
* Spring's Type Conversion"](http://docs.spring.io/spring/docs/current/spring-framework-reference/html/validation.html#core-convert) for more details.
*
* @param objectToSave the object to store in the collection
* @return
*/
suspend fun <T> save(objectToSave: T): T?
/**
* Save the object to the specified collection. This will perform an insert if the object is not already present, that
* is an 'upsert'.
*
*
* The object is converted to the MongoDB native representation using an instance of {@see MongoConverter}. Unless
* configured otherwise, an instance of [MappingMongoConverter] will be used.
*
*
* If you object has an "Id' property, it will be set with the generated Id from MongoDB. If your Id property is a
* String then MongoDB ObjectId will be used to populate that string. Otherwise, the conversion from ObjectId to your
* property type will be handled by Spring's BeanWrapper class that leverages Type Conversion API. See <a http:></a>//docs.spring.io/spring/docs/current/spring-framework-reference/html/validation.html#core-convert">Spring's
* Type Conversion" for more details.
*
* @param objectToSave the object to store in the collection
* @param collectionName name of the collection to store the object in
* @return
*/
suspend fun <T> save(objectToSave: T, collectionName: String): T?
/**
* Save the object to the collection for the entity type of the object to save. This will perform an insert if the
* object is not already present, that is an 'upsert'.
*
*
* The object is converted to the MongoDB native representation using an instance of {@see MongoConverter}. Unless
* configured otherwise, an instance of [MappingMongoConverter] will be used.
*
*
* If you object has an "Id' property, it will be set with the generated Id from MongoDB. If your Id property is a
* String then MongoDB ObjectId will be used to populate that string. Otherwise, the conversion from ObjectId to your
* property type will be handled by Spring's BeanWrapper class that leverages Type Conversion API. See
* [
* Spring's Type Conversion"](http://docs.spring.io/spring/docs/current/spring-framework-reference/html/validation.html#core-convert) for more details.
*
* @param objectToSave the object to store in the collection
* @return
*/
suspend fun <T> save(objectToSave: suspend () -> T?): T?
/**
* Save the object to the specified collection. This will perform an insert if the object is not already present, that
* is an 'upsert'.
*
*
* The object is converted to the MongoDB native representation using an instance of {@see MongoConverter}. Unless
* configured otherwise, an instance of [MappingMongoConverter] will be used.
*
*
* If you object has an "Id' property, it will be set with the generated Id from MongoDB. If your Id property is a
* String then MongoDB ObjectId will be used to populate that string. Otherwise, the conversion from ObjectId to your
* property type will be handled by Spring's BeanWrapper class that leverages Type Conversion API. See <a http:></a>//docs.spring.io/spring/docs/current/spring-framework-reference/html/validation.html#core-convert">Spring's
* Type Conversion" for more details.
*
* @param objectToSave the object to store in the collection
* @param collectionName name of the collection to store the object in
* @return
*/
suspend fun <T> save(objectToSave: suspend () -> T?, collectionName: String): T?
/**
* Performs an upsert. If no document is found that matches the query, a new document is created and inserted by
* combining the query document and the update document.
*
* @param query the query document that specifies the criteria used to select a record to be upserted
* @param update the update document that contains the updated object or $ operators to manipulate the existing object
* @param entityClass class that determines the collection to use
* @return the WriteResult which lets you access the results of the previous write.
*/
suspend fun upsert(query: Query, update: Update, entityClass: Class<*>): UpdateResult?
/**
* Performs an upsert. If no document is found that matches the query, a new document is created and inserted by
* combining the query document and the update document. <br></br>
* **NOTE:** Any additional support for field mapping, versions, etc. is not available due to the lack of
* domain type information. Use [.upsert] to get full type specific support.
*
* @param query the query document that specifies the criteria used to select a record to be updated
* @param update the update document that contains the updated object or $ operators to manipulate the existing
* object.
* @param collectionName name of the collection to update the object in
* @return the WriteResult which lets you access the results of the previous write.
*/
suspend fun upsert(query: Query, update: Update, collectionName: String): UpdateResult?
/**
* Performs an upsert. If no document is found that matches the query, a new document is created and inserted by
* combining the query document and the update document.
*
* @param query the query document that specifies the criteria used to select a record to be upserted
* @param update the update document that contains the updated object or $ operators to manipulate the existing object
* @param entityClass class of the pojo to be operated on
* @param collectionName name of the collection to update the object in
* @return the WriteResult which lets you access the results of the previous write.
*/
suspend fun upsert(query: Query, update: Update, entityClass: Class<*>, collectionName: String): UpdateResult?
/**
* Updates the first object that is found in the collection of the entity class that matches the query document with
* the provided update document.
*
* @param query the query document that specifies the criteria used to select a record to be updated
* @param update the update document that contains the updated object or $ operators to manipulate the existing
* object.
* @param entityClass class that determines the collection to use
* @return the WriteResult which lets you access the results of the previous write.
*/
suspend fun updateFirst(query: Query, update: Update, entityClass: Class<*>): UpdateResult?
/**
* Updates the first object that is found in the specified collection that matches the query document criteria with
* the provided updated document. <br></br>
* **NOTE:** Any additional support for field mapping, versions, etc. is not available due to the lack of
* domain type information. Use [.updateFirst] to get full type specific support.
*
* @param query the query document that specifies the criteria used to select a record to be updated
* @param update the update document that contains the updated object or $ operators to manipulate the existing
* object.
* @param collectionName name of the collection to update the object in
* @return the WriteResult which lets you access the results of the previous write.
*/
suspend fun updateFirst(query: Query, update: Update, collectionName: String): UpdateResult?
/**
* Updates the first object that is found in the specified collection that matches the query document criteria with
* the provided updated document. <br></br>
* **NOTE:** Any additional support for field mapping, versions, etc. is not available due to the lack of
* domain type information. Use [.updateFirst] to get full type specific support.
*
* @param query the query document that specifies the criteria used to select a record to be updated
* @param update the update document that contains the updated object or $ operators to manipulate the existing
* object.
* @param entityClass class of the pojo to be operated on
* @param collectionName name of the collection to update the object in
* @return the WriteResult which lets you access the results of the previous write.
*/
suspend fun updateFirst(query: Query, update: Update, entityClass: Class<*>, collectionName: String): UpdateResult?
/**
* Updates all objects that are found in the collection for the entity class that matches the query document criteria
* with the provided updated document.
*
* @param query the query document that specifies the criteria used to select a record to be updated
* @param update the update document that contains the updated object or $ operators to manipulate the existing
* object.
* @param entityClass class that determines the collection to use
* @return the WriteResult which lets you access the results of the previous write.
*/
suspend fun updateMulti(query: Query, update: Update, entityClass: Class<*>): UpdateResult?
/**
* Updates all objects that are found in the specified collection that matches the query document criteria with the
* provided updated document. <br></br>
* **NOTE:** Any additional support for field mapping, versions, etc. is not available due to the lack of
* domain type information. Use [.updateMulti] to get full type specific support.
*
* @param query the query document that specifies the criteria used to select a record to be updated
* @param update the update document that contains the updated object or $ operators to manipulate the existing
* object.
* @param collectionName name of the collection to update the object in
* @return the WriteResult which lets you access the results of the previous write.
*/
suspend fun updateMulti(query: Query, update: Update, collectionName: String): UpdateResult?
/**
* Updates all objects that are found in the collection for the entity class that matches the query document criteria
* with the provided updated document.
*
* @param query the query document that specifies the criteria used to select a record to be updated
* @param update the update document that contains the updated object or $ operators to manipulate the existing
* object.
* @param entityClass class of the pojo to be operated on
* @param collectionName name of the collection to update the object in
* @return the WriteResult which lets you access the results of the previous write.
*/
suspend fun updateMulti(query: Query, update: Update, entityClass: Class<*>, collectionName: String): UpdateResult?
/**
* Remove the given object from the collection by id.
*
* @param object
* @return
*/
suspend fun remove(`object`: Any): DeleteResult?
/**
* Removes the given object from the given collection.
*
* @param object
* @param collection must not be null or empty.
*/
suspend fun remove(`object`: Any, collection: String): DeleteResult?
/**
* Remove the given object from the collection by id.
*
* @param objectToRemove
* @return
*/
suspend fun remove(objectToRemove: suspend () -> Any?): DeleteResult?
/**
* Removes the given object from the given collection.
*
* @param objectToRemove
* @param collection must not be null or empty.
* @return
*/
suspend fun remove(objectToRemove: () -> Any?, collection: String): DeleteResult?
/**
* Remove all documents that match the provided query document criteria from the the collection used to store the
* entityClass. The Class parameter is also used to help convert the Id of the object if it is present in the query.
*
* @param query
* @param entityClass
* @return
*/
suspend fun remove(query: Query, entityClass: Class<*>): DeleteResult?
/**
* Remove all documents that match the provided query document criteria from the the collection used to store the
* entityClass. The Class parameter is also used to help convert the Id of the object if it is present in the query.
*
* @param query
* @param entityClass
* @param collectionName
* @return
*/
suspend fun remove(query: Query, entityClass: Class<*>, collectionName: String): DeleteResult?
/**
* Remove all documents from the specified collection that match the provided query document criteria. There is no
* conversion/mapping done for any criteria using the id field. <br></br>
* **NOTE:** Any additional support for field mapping is not available due to the lack of domain type
* information. Use [.remove] to get full type specific support.
*
* @param query the query document that specifies the criteria used to remove a record
* @param collectionName name of the collection where the objects will removed
*/
suspend fun remove(query: Query, collectionName: String): DeleteResult?
/**
* Returns and removes all documents form the specified collection that match the provided query. <br></br>
* **NOTE:** Any additional support for field mapping is not available due to the lack of domain type
* information. Use [.findAllAndRemove] to get full type specific support.
*
* @param query
* @param collectionName
* @return
*/
suspend fun <T> findAllAndRemove(query: Query, collectionName: String): List<T>