-
Notifications
You must be signed in to change notification settings - Fork 28
/
Grijjy.MongoDB.Queries.pas
4302 lines (3423 loc) · 126 KB
/
Grijjy.MongoDB.Queries.pas
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
unit Grijjy.MongoDB.Queries;
(*< Tools for building MongoDB queries.
@bold(Quick Start)
<source>
var
Filter: TgoMongoFilter;
Projection: TgoMongoProjection;
Sort: TgoMongoSort;
Update: TgoMongoUpdate;
begin
Filter := TgoMongoFilter.Gte('age', 21) and TgoMongoFilter.Lt('age', 65');
WriteLn(Filter.ToJson); // outputs: {age: {$gte: 21, $lt: 65}}
Projection := TgoMongoProjection.Include('name') + TgoMongoProjection.Exclude('_id');
WriteLn(Projection.ToJson); // outputs: {name: 1, _id: 0}
Sort := TgoMongoSort.Decending('age') + TgoMongoSort.Ascending('posts');
WriteLn(Sort.ToJson); // outputs: {age: -1, posts: 1}
Update := TgoMongoUpdate.Init.&Set('age', 42).&Set('name', 'Joe');
WriteLn(Update.ToJson); // outputs {$set: {age: 42, name: "Joe"}}
end;
</source>
@bold(Query Tools)
Filters (TgoMongoFilter), projections (TgoMongoProjection), sort modifiers
(TgrMongoSort) and update definitions (TgrMongoUpdate) can be implictly
converted from JSON strings and documents, or they can be created using
static helper functions. The following 3 statements all have the same result:
<source>
MyFilter := '{age: {$gt: 18}}';
MyFilter := TgoBsonDocument.Create('age', TgoBsonDocument.Create('$gt', 18));
MyFilter := TgoMongoFilter.Gt('age', 18);
</source>
They can be converted to BSON documents using the Render method, or to JSON
and BSON using to ToJson and ToBson methods.
@bold(TgoMongoFilter)
Comparision:
* TgoMongoFilter.Eq
* TgoMongoFilter.Ne
* TgoMongoFilter.Lt
* TgoMongoFilter.Lte
* TgoMongoFilter.Gt
* TgoMongoFilter.Gte
Logical:
* TgoMongoFilter.LogicalAnd
* TgoMongoFilter.LogicalOr
* TgoMongoFilter.LogicalNot
* TgoMongoFilter.And
* TgoMongoFilter.Or
* TgoMongoFilter.Not
Element:
* TgoMongoFilter.Exists
* TgoMongoFilter.Type
Evaluation:
* TgoMongoFilter.Mod
* TgoMongoFilter.Regex
* TgoMongoFilter.Text
Array:
* TgoMongoFilter.AnyEq
* TgoMongoFilter.AnyNe
* TgoMongoFilter.AnyLt
* TgoMongoFilter.AnyLte
* TgoMongoFilter.AnyGt
* TgoMongoFilter.AnyGte
* TgoMongoFilter.All
* TgoMongoFilter.In
* TgoMongoFilter.Nin
* TgoMongoFilter.ElemMatch
* TgoMongoFilter.Size
* TgoMongoFilter.SizeGt
* TgoMongoFilter.SizeGte
* TgoMongoFilter.SizeLt
* TgoMongoFilter.SizeLte
Bitwise:
* TgoMongoFilter.BitsAllClear
* TgoMongoFilter.BitsAllSet
* TgoMongoFilter.BitsAnyClear
* TgoMongoFilter.BitsAnySet
@bold(TgoMongoProjection)
* TgoMongoProjection.Include
* TgoMongoProjection.Exclude
* TgoMongoProjection.ElemMatch
* TgoMongoProjection.MetaTextScore
* TgoMongoProjection.Slice
* TgoMongoProjection.Add
* TgoMongoProjection.Combine
@bold(TgrMongoSort)
* TgoMongoSort.Ascending
* TgoMongoSort.Descending
* TgoMongoSort.MetaTextScore
* TgoMongoSort.Add
* TgoMongoSort.Combine
@bold(TgrMongoUpdate)
Fields:
* TgoMongoUpdate.Set
* TgoMongoUpdate.SetOnInsert
* TgoMongoUpdate.Unset
* TgoMongoUpdate.Inc
* TgoMongoUpdate.Mul
* TgoMongoUpdate.Max
* TgoMongoUpdate.Min
* TgoMongoUpdate.CurrentDate
* TgoMongoUpdate.Rename
Array:
* TgoMongoUpdate.AddToSet
* TgoMongoUpdate.AddToSetEach
* TgoMongoUpdate.PopFirst
* TgoMongoUpdate.PopLast
* TgoMongoUpdate.Pull
* TgoMongoUpdate.PullFilter
* TgoMongoUpdate.PullAll
* TgoMongoUpdate.Push
* TgoMongoUpdate.PushEach
Bitwise:
* TgoMongoUpdate.BitwiseAnd
* TgoMongoUpdate.BitwiseOr
* TgoMongoUpdate.BitwiseXor *)
{$INCLUDE 'Grijjy.inc'}
interface
uses
System.SysUtils,
Grijjy.Bson;
type
{ Text searching options for TgoMongoFilter.Text }
TgoMongoTextSearchOption = (
{ The enable case sensitive search }
CaseSensitive,
{ The enable diacritic sensitive search }
DiacriticSensitive);
type
{ Set of text search options }
TgoMongoTextSearchOptions = set of TgoMongoTextSearchOption;
type
(* A MongoDB filter. A filter defines a query criterion. For example, the
filter <tt>{ age : { $gt: 18 } }</tt> can be used to query persons more
than 18 years old.
Filters can be implictly converted from JSON strings and documents, or they
can be created using static helper functions. The following 3 statements
all have the same result:
<source>
MyFilter := '{age: {$gt: 18}}';
MyFilter := TgoBsonDocument.Create('age', TgoBsonDocument.Create('$gt', 18));
MyFilter := TgoMongoFilter.Gt('age', 18);
</source>
You can use the logical "and", "or" and "not" operators to combine multiple
filters into one:
<source>
MyFilter := TgoMongoFilter.Gt('a', 1) and TgoMongoFilter.Lt('a', 10);
</source>
This results in: <tt>{a: {$gt: 1, $lt: 10}}</tt> *)
TgoMongoFilter = record
{$REGION 'Internal Declarations'}
private type
IFilter = interface
['{BAE9502F-7FC3-4AB4-B35F-AEA09F8BC0DB}']
function Render: TgoBsonDocument;
function ToBson: TBytes;
function ToJson(const ASettings: TgoJsonWriterSettings): String;
end;
private class var
FEmpty: TgoMongoFilter;
private
FImpl: IFilter;
public
class constructor Create;
{$ENDREGION 'Internal Declarations'}
public
(* Implicitly converts a Json string to a filter. Use this converter if you
have manually created a query criterion in Json (such
as <tt>{ age : { $gt: 18 } }</tt>) and want to use it as a filter.
The Json string must be parseable to a BSON document.
Raises:
EgrJsonParserError or EInvalidOperation on parse errors *)
class operator Implicit(const AJson: String): TgoMongoFilter; static;
(* Implicitly converts a BSON Document to a filter. Use this converter if you
have manually created a BSON document for a query criterion, and want to
use it as a filter. *)
class operator Implicit(const ADocument: TgoBsonDocument): TgoMongoFilter; static;
(* Checks if the filter has been assigned.
Returns:
True if the filter hasn't been assigned yet. *)
function IsNil: Boolean; inline;
{ Unassigns the filter (like setting an object to nil).
IsNil will return True afterwards. }
procedure SetNil; inline;
(* Renders the filter to a BSON Document.
Returns:
The BSON Document that represents this filter. *)
function Render: TgoBsonDocument; inline;
(* Converts the filter to binary BSON.
Returns:
The BSON byte stream that represents this filter. *)
function ToBson: TBytes; inline;
(* Converts the filter to a JSON string.
Returns:
This filter in JSON format.
@bold(Note): the filter is converted using the default writer settings.
That is, without any pretty printing, and in Strict mode. Use the other
overload of this function to specify output settings. *)
function ToJson: String; overload; inline;
(* Converts the filter to a JSON string, using specified settings.
Parameters:
ASettings: the output settings to use, such as pretty-printing and
Strict vs Shell mode.
Returns:
This filter in JSON format. *)
function ToJson(const ASettings: TgoJsonWriterSettings): String; overload; inline;
{ Empty filter. An empty filter matches everything. }
class property Empty: TgoMongoFilter read FEmpty;
public
{===================================
Comparison
===================================}
(* Matches values that are equal to a specified value.
Parameters:
AFieldName: the name of the field (left operand).
AValue: the value (right operand).
Returns:
The filter.
Example: <code>TgoMongoFilter.Eq('x', 1)</code>
results in <tt>{x: 1}</tt>
See https://docs.mongodb.org/manual/reference/operator/query/eq/#op._S_eq *)
class function Eq(const AFieldName: String;
const AValue: TgoBsonValue): TgoMongoFilter; static;
(* Matches values that are @bold(not) equal to a specified value.
Parameters:
AFieldName: the name of the field (left operand).
AValue: the value (right operand).
Returns:
The filter.
Example: <code>TgoMongoFilter.Ne('x', 1)</code>
results in <tt>{x: {$ne: 1}}</tt>
See https://docs.mongodb.org/manual/reference/operator/query/ne/#op._S_ne *)
class function Ne(const AFieldName: String;
const AValue: TgoBsonValue): TgoMongoFilter; static;
(* Matches values that are less than a specified value.
Parameters:
AFieldName: the name of the field (left operand).
AValue: the value (right operand).
Returns:
The filter.
Example: <code>TgoMongoFilter.Lt('x', 1)</code>
results in <tt>{x: {$lt: 1}}</tt>
See https://docs.mongodb.org/manual/reference/operator/query/lt/#op._S_lt *)
class function Lt(const AFieldName: String;
const AValue: TgoBsonValue): TgoMongoFilter; static;
(* Matches values that are less than or equal to a specified value.
Parameters:
AFieldName: the name of the field (left operand).
AValue: the value (right operand).
Returns:
The filter.
Example: <code>TgoMongoFilter.Lte('x', 1)</code>
results in <tt>{x: {$lte: 1}}</tt>
See https://docs.mongodb.org/manual/reference/operator/query/lte/#op._S_lte *)
class function Lte(const AFieldName: String;
const AValue: TgoBsonValue): TgoMongoFilter; static;
(* Matches values that are greater than a specified value.
Parameters:
AFieldName: the name of the field (left operand).
AValue: the value (right operand).
Returns:
The filter.
Example: <code>TgoMongoFilter.Gt('x', 1)</code>
results in <tt>{x: {$gt: 1}}</tt>
See https://docs.mongodb.org/manual/reference/operator/query/gt/#op._S_gt *)
class function Gt(const AFieldName: String;
const AValue: TgoBsonValue): TgoMongoFilter; static;
(* Matches values that are greater than or equal to a specified value.
Parameters:
AFieldName: the name of the field (left operand).
AValue: the value (right operand).
Returns:
The filter.
Example: <code>TgoMongoFilter.Gte('x', 1)</code>
results in <tt>{x: {$gte: 1}}</tt>
See https://docs.mongodb.org/manual/reference/operator/query/gte/#op._S_gte *)
class function Gte(const AFieldName: String;
const AValue: TgoBsonValue): TgoMongoFilter; static;
public
{===================================
Logical
===================================}
(* Joins query clauses with a logical AND returns all documents that match
the conditions of both clauses. For example:
<source>
Filter := TgoMongoFilter.Eq('x', 1) and TgoMongoFilter.Eq('y', 2);
</source>
will result in <tt>{x: 1, y: 2}</tt>.
Depending on the source filters, the output may be different.
For example:
<source>
Filter := TgoMongoFilter.Gt('x', 1) and TgoMongoFilter.Lt('x', 10);
</source>
will result in <tt>{x: {$gt: 1, $lt: 10}}</tt>
See https://docs.mongodb.org/manual/reference/operator/query/and/#op._S_and *)
class operator LogicalAnd(const ALeft, ARight: TgoMongoFilter): TgoMongoFilter; static;
(* Joins query clauses with a logical OR returns all documents that match
the conditions of either clause. For example:
<source>
Filter := TgoMongoFilter.Eq('x', 1) or TgoMongoFilter.Eq('y', 2);
</source>
will result in <tt>{$or: [{x: 1}, {y: 2}]}</tt>.
See https://docs.mongodb.org/manual/reference/operator/query/or/#op._S_or *)
class operator LogicalOr(const ALeft, ARight: TgoMongoFilter): TgoMongoFilter; static;
(* Inverts the effect of a query expression and returns documents that do
not match the query expression. For example:
<source>
Filter := not TgoMongoFilter.Eq('x', 1);
</source>
will result in <tt>{x: {$ne: 1}}</tt>.
See https://docs.mongodb.org/manual/reference/operator/query/not/#op._S_not *)
class operator LogicalNot(const AOperand: TgoMongoFilter): TgoMongoFilter; static;
(* Joins query clauses with a logical AND returns all documents that match
the conditions of both clauses. For example:
Parameters:
AFilter1: the first filter.
AFilter2: the second filter.
Returns:
The AND filter.
<source>
Filter := TgoMongoFilter.&And(
TgoMongoFilter.Eq('x', 1),
TgoMongoFilter.Eq('y', 2));
</source>
will result in <tt>{x: 1, y: 2}</tt>.
Depending on the source filters, the output may be different.
For example:
<source>
Filter := TgoMongoFilter.&And(
TgoMongoFilter.Gt('x', 1),
TgoMongoFilter.Lt('x', 10));
</source>
will result in <tt>{x: {$gt: 1, $lt: 10}}</tt>
See https://docs.mongodb.org/manual/reference/operator/query/and/#op._S_and *)
class function &And(const AFilter1,
AFilter2: TgoMongoFilter): TgoMongoFilter; overload; static;
(* Joins query clauses with a logical AND returns all documents that match
the conditions of both clauses. For example:
Parameters:
AFilters: the filters to combine.
Returns:
The AND filter.
<source>
Filter := TgoMongoFilter.&And([
TgoMongoFilter.Eq('x', 1),
TgoMongoFilter.Eq('y', 2),
TgoMongoFilter.Eq('z', 3)]);
</source>
will result in <tt>{x: 1, y: 2, z: 3}</tt>.
Depending on the source filter, the output may be different. For example:
<source>
Filter := TgoMongoFilter.&And([
TgoMongoFilter.Eq('x', 1),
TgoMongoFilter.Eq('x', 2),
TgoMongoFilter.Eq('z', 3)]);
</source>
will result in <tt>{$and: [{x: 1}, {x: 2}, {z: 3}]}</tt>
See https://docs.mongodb.org/manual/reference/operator/query/and/#op._S_and *)
class function &And(
const AFilters: array of TgoMongoFilter): TgoMongoFilter; overload; static;
(* Joins query clauses with a logical OR returns all documents that match
the conditions of either clause. For example:
Parameters:
AFilter1: the first filter.
AFilter2: the second filter.
Returns:
The OR filter.
<source>
Filter := TgoMongoFilter.Eq('x', 1) or TgoMongoFilter.Eq('y', 2);
</source>
will result in <tt>{$or: [{x: 1}, {y: 2}]}</tt>.
See https://docs.mongodb.org/manual/reference/operator/query/or/#op._S_or *)
class function &Or(const AFilter1,
AFilter2: TgoMongoFilter): TgoMongoFilter; overload; static;
(* Joins query clauses with a logical OR returns all documents that match
the conditions of either clause. For example:
Parameters:
AFilters: the filters to combine.
Returns:
The OR filter.
<source>
Filter := TgoMongoFilter.Eq('x', 1) or TgoMongoFilter.Eq('y', 2);
</source>
will result in <tt>{$or: [{x: 1}, {y: 2}]}</tt>.
See https://docs.mongodb.org/manual/reference/operator/query/or/#op._S_or *)
class function &Or(
const AFilters: array of TgoMongoFilter): TgoMongoFilter; overload; static;
(* Inverts the effect of a query expression and returns documents that do
not match the query expression. For example:
Parameters:
AOperand: the filter to negate.
Returns:
The NOT filter.
<source>
Filter := TgoMongoFilter.&Not(TgoMongoFilter.Eq('x', 1));
</source>
will result in <tt>{x: {$ne: 1}}</tt>.
See https://docs.mongodb.org/manual/reference/operator/query/not/#op._S_not *)
class function &Not(const AOperand: TgoMongoFilter): TgoMongoFilter; static;
public
{===================================
Element
===================================}
(* Matches documents that have (or have not) the specified field.
Parameters:
AFieldName: the name of the field (left operand).
AExists: (optional) whether the field must exist or not (right
operand). Defaults to True.
Returns:
The filter.
Example: <code>TgoMongoFilter.Exists('x')</code>
results in <tt>{x: {$exists: true}}</tt>
See https://docs.mongodb.org/manual/reference/operator/query/exists/#op._S_exists *)
class function Exists(const AFieldName: String;
const AExists: Boolean = True): TgoMongoFilter; static;
(* Selects documents if a field is of the specified type.
Parameters:
AFieldName: the name of the field (left operand).
AType: the BSON type to match (right operand).
Returns:
The filter.
Example: <code>TgoMongoFilter.&Type('x', TgtBsonType.&String)</code>
results in <tt>{x: {$type: 2}}</tt>
See https://docs.mongodb.org/manual/reference/operator/query/type/#op._S_type *)
class function &Type(const AFieldName: String;
const AType: TgoBsonType): TgoMongoFilter; overload; static;
(* Selects documents if a field is of the specified type.
Parameters:
AFieldName: the name of the field (left operand).
AType: the string alias for the BSON type to match (right operand).
Returns:
The filter.
Example: <code>TgoMongoFilter.&Type('x', 'string')</code>
results in <tt>{x: {$type: "string"}}</tt>
See https://docs.mongodb.org/manual/reference/operator/query/type/#op._S_type *)
class function &Type(const AFieldName, AType: String): TgoMongoFilter; overload; static;
public
{===================================
Evaluation
===================================}
(* Select documents where the value of a field divided by a divisor has the
specified remainder (i.e. perform a modulo operation to select documents).
Parameters:
AFieldName: the name of the field (left operand).
ADivisor: the divisor.
ARemainder: the remainder.
Returns:
The filter.
Example: <code>TgoMongoFilter.&Mod('x', 10, 4)</code>
results in <tt>{x: {$mod: [NumberLong(10), NumberLong(4)]}}</tt>
See https://docs.mongodb.org/manual/reference/operator/query/mod/#op._S_mod *)
class function &Mod(const AFieldName: String;
const ADivisor, ARemainder: Int64): TgoMongoFilter; static;
(* Selects documents where values match a specified regular expression.
Parameters:
AFieldName: the name of the field (left operand).
ARegex: the regular expression.
Returns:
The filter.
Example: <code>TgoMongoFilter.Regex('x', '/abc/')</code>
results in <tt>{x: /abc/}</tt>
See https://docs.mongodb.org/manual/reference/operator/query/regex/#op._S_regex *)
class function Regex(const AFieldName: String;
const ARegex: TgoBsonRegularExpression): TgoMongoFilter; static;
(* Performs a text search.
Parameters:
AText: a string of terms that MongoDB parses and uses to query the text
index. MongoDB performs a logical OR search of the terms unless
specified as a phrase.
AOptions: (optional) text search options. Defaults to none.
ALanguage: (optional) language that determines the list of stop words
for the search and the rules for the stemmer and tokenizer. If not
specified, the search uses the default language of the index.
Returns:
The filter.
Example: <code>TgoMongoFilter.Text('funny', [TgrMongoTextSearchOption.CaseSensitive])</code>
results in <tt>{$text: {$search: "funny", $caseSensitive: true}}</tt>
See https://docs.mongodb.org/manual/reference/operator/query/text/#op._S_text *)
class function Text(const AText: String;
const AOptions: TgoMongoTextSearchOptions = [];
const ALanguage: String = ''): TgoMongoFilter; static;
public
{===================================
Array
===================================}
(* Matches values where an array field contains any element with a
specific value.
Parameters:
AFieldName: the name of the field (left operand).
AValue: the value (right operand).
Returns:
The filter.
Example: <code>TgoMongoFilter.AnyEq('x', 1)</code>
results in <tt>{x: 1}</tt>
See https://docs.mongodb.org/manual/reference/operator/query/eq/#op._S_eq *)
class function AnyEq(const AFieldName: String;
const AValue: TgoBsonValue): TgoMongoFilter; static;
(* Matches values where an array field contains any element not qual to a
specific value.
Parameters:
AFieldName: the name of the field (left operand).
AValue: the value (right operand).
Returns:
The filter.
Example: <code>TgoMongoFilter.AnyNe('x', 1)</code>
results in <tt>{x: {$ne: 1}}</tt>
See https://docs.mongodb.org/manual/reference/operator/query/ne/#op._S_ne *)
class function AnyNe(const AFieldName: String;
const AValue: TgoBsonValue): TgoMongoFilter; static;
(* Matches values where an array field contains any element with a value
less than a specific value.
Parameters:
AFieldName: the name of the field (left operand).
AValue: the value (right operand).
Returns:
The filter.
Example: <code>TgoMongoFilter.AnyLt('x', 1)</code>
results in <tt>{x: {$lt: 1}}</tt>
See https://docs.mongodb.org/manual/reference/operator/query/lt/#op._S_lt *)
class function AnyLt(const AFieldName: String;
const AValue: TgoBsonValue): TgoMongoFilter; static;
(* Matches values where an array field contains any element with a value
less than or equal to a specific value.
Parameters:
AFieldName: the name of the field (left operand).
AValue: the value (right operand).
Returns:
The filter.
Example: <code>TgoMongoFilter.AnyLte('x', 1)</code>
results in <tt>{x: {$lte: 1}}</tt>
See https://docs.mongodb.org/manual/reference/operator/query/lte/#op._S_lte *)
class function AnyLte(const AFieldName: String;
const AValue: TgoBsonValue): TgoMongoFilter; static;
(* Matches values where an array field contains any element with a value
greater than a specific value.
Parameters:
AFieldName: the name of the field (left operand).
AValue: the value (right operand).
Returns:
The filter.
Example: <code>TgoMongoFilter.AnyGt('x', 1)</code>
results in <tt>{x: {$gt: 1}}</tt>
See https://docs.mongodb.org/manual/reference/operator/query/gt/#op._S_gt *)
class function AnyGt(const AFieldName: String;
const AValue: TgoBsonValue): TgoMongoFilter; static;
(* Matches values where an array field contains any element with a value
greater than or equal to a specific value.
Parameters:
AFieldName: the name of the field (left operand).
AValue: the value (right operand).
Returns:
The filter.
Example: <code>TgoMongoFilter.AnyGte('x', 1)</code>
results in <tt>{x: {$gte: 1}}</tt>
See https://docs.mongodb.org/manual/reference/operator/query/gte/#op._S_gte *)
class function AnyGte(const AFieldName: String;
const AValue: TgoBsonValue): TgoMongoFilter; static;
(* Creates an All filter for an array field.
Parameters:
AFieldName: the name of the field (left operand).
AValues: the array values (right operand).
Returns:
The filter.
Example: <code>TgoMongoFilter.All('x', [1, 2])</code>
results in <tt>{x: {$all: [1, 2]}}</tt> *)
class function All(const AFieldName: String;
const AValues: TArray<TgoBsonValue>): TgoMongoFilter; overload; static;
(* Matches arrays that contain all elements specified in the query.
Parameters:
AFieldName: the name of the field (left operand).
AValues: the array values (right operand).
Returns:
The filter.
Example: <code>TgoMongoFilter.All('x', [1, 2])</code>
results in <tt>{x: {$all: [1, 2]}}</tt> *)
class function All(const AFieldName: String;
const AValues: array of TgoBsonValue): TgoMongoFilter; overload; static;
(* Matches arrays that contain all elements specified in the query.
Parameters:
AFieldName: the name of the field (left operand).
AValues: the BSON Array (right operand).
Returns:
The filter.
Example: <code>TgoMongoFilter.All('x', TgoBsonArray.Create([1, 2]))</code>
results in <tt>{x: {$all: [1, 2]}}</tt>
See https://docs.mongodb.org/manual/reference/operator/query/all/#op._S_all *)
class function All(const AFieldName: String;
const AValues: TgoBsonArray): TgoMongoFilter; overload; static;
(* Matches any of the values specified in an array.
Parameters:
AFieldName: the name of the field (left operand).
AValues: the array values (right operand).
Returns:
The filter.
Example: <code>TgoMongoFilter.In('x', [1, 2])</code>
results in <tt>{x: {$in: [1, 2]}}</tt>
See https://docs.mongodb.org/manual/reference/operator/query/in/#op._S_in *)
class function &In(const AFieldName: String;
const AValues: TArray<TgoBsonValue>): TgoMongoFilter; overload; static;
(* Matches any of the values specified in an array.
Parameters:
AFieldName: the name of the field (left operand).
AValues: the array values (right operand).
Returns:
The filter.
Example: <code>TgoMongoFilter.In('x', [1, 2])</code>
results in <tt>{x: {$in: [1, 2]}}</tt>
See https://docs.mongodb.org/manual/reference/operator/query/in/#op._S_in *)
class function &In(const AFieldName: String;
const AValues: array of TgoBsonValue): TgoMongoFilter; overload; static;
(* Matches any of the values specified in an array.
Parameters:
AFieldName: the name of the field (left operand).
AValues: the BSON Array (right operand).
Returns:
The filter.
Example: <code>TgoMongoFilter.In('x', TgoBsonArray.Create([1, 2]))</code>
results in <tt>{x: {$in: [1, 2]}}</tt>
See https://docs.mongodb.org/manual/reference/operator/query/in/#op._S_in *)
class function &In(const AFieldName: String;
const AValues: TgoBsonArray): TgoMongoFilter; overload; static;
(* Matches none of the values specified in an array.
Parameters:
AFieldName: the name of the field (left operand).
AValues: the array values (right operand).
Returns:
The filter.
Example: <code>TgoMongoFilter.Nin('x', [1, 2])</code>
results in <tt>{x: {$nin: [1, 2]}}</tt>
See https://docs.mongodb.org/manual/reference/operator/query/nin/#op._S_nin *)
class function Nin(const AFieldName: String;
const AValues: TArray<TgoBsonValue>): TgoMongoFilter; overload; static;
(* Matches none of the values specified in an array.
Parameters:
AFieldName: the name of the field (left operand).
AValues: the array values (right operand).
Returns:
The filter.
Example: <code>TgoMongoFilter.Nin('x', [1, 2])</code>
results in <tt>{x: {$nin: [1, 2]}}</tt>
See https://docs.mongodb.org/manual/reference/operator/query/nin/#op._S_nin *)
class function Nin(const AFieldName: String;
const AValues: array of TgoBsonValue): TgoMongoFilter; overload; static;
(* Matches none of the values specified in an array.
Parameters:
AFieldName: the name of the field (left operand).
AValues: the BSON Array (right operand).
Returns:
The filter.
Example: <code>TgoMongoFilter.Nin('x', TgoBsonArray.Create([1, 2]))</code>
results in <tt>{x: {$nin: [1, 2]}}</tt>
See https://docs.mongodb.org/manual/reference/operator/query/nin/#op._S_nin *)
class function Nin(const AFieldName: String;
const AValues: TgoBsonArray): TgoMongoFilter; overload; static;
(* Selects documents if element in the array field matches all the specified
conditions.
Parameters:
AFieldName: the name of the field (left operand).
AFilter: the filter specifying the conditions (right operand).
Returns:
The filter.
Example: <code>TgoMongoFilter.ElemMatch('Enabled', TgoMongoFilter.Eq('k', 0) and TgoMongoFilter.Eq('v', True))</code>
results in <tt>{Enabled: {$elemMatch: { k: 0, v: true}}}</tt>
See https://docs.mongodb.org/manual/reference/operator/query/elemMatch/#op._S_elemMatch *)
class function ElemMatch(const AFieldName: String;
const AFilter: TgoMongoFilter): TgoMongoFilter; overload; static;
(* Selects documents if the array field is a specified size.
Parameters:
AFieldName: the name of the field (left operand).
ASize: the size (aka length or count) of the array (right operand).
Returns:
The filter.
Example: <code>TgoMongoFilter.Size('x', 10)</code>
results in <tt>{x: {$size: 10}}</tt>
See https://docs.mongodb.org/manual/reference/operator/query/size/#op._S_size *)
class function Size(const AFieldName: String;
const ASize: Integer): TgoMongoFilter; overload; static;
(* Selects documents if the array field is greater than a specified size.
Parameters:
AFieldName: the name of the field (left operand).
ASize: the size (aka length or count) of the array (right operand).
Returns:
The filter.
Example: <code>TgoMongoFilter.SizeGt('x', 10)</code>
results in <tt>{"x.10": {$exists: true}}</tt> *)
class function SizeGt(const AFieldName: String;
const ASize: Integer): TgoMongoFilter; overload; static;
(* Selects documents if the array field is greater than or equal to a
specified size.
Parameters:
AFieldName: the name of the field (left operand).
ASize: the size (aka length or count) of the array (right operand).
Returns:
The filter.
Example: <code>TgoMongoFilter.SizeGt('x', 10)</code>
results in <tt>{"x.9": {$exists: true}}</tt> *)
class function SizeGte(const AFieldName: String;
const ASize: Integer): TgoMongoFilter; overload; static;
(* Selects documents if the array field is less than a specified size.
Parameters:
AFieldName: the name of the field (left operand).
ASize: the size (aka length or count) of the array (right operand).
Returns:
The filter.
Example: <code>TgoMongoFilter.SizeLt('x', 10)</code>
results in <tt>{"x.9": {$exists: false}}</tt> *)
class function SizeLt(const AFieldName: String;
const ASize: Integer): TgoMongoFilter; overload; static;
(* Selects documents if the array field is less than or equal to a
specified size.
Parameters:
AFieldName: the name of the field (left operand).
ASize: the size (aka length or count) of the array (right operand).
Returns:
The filter.
Example: <code>TgoMongoFilter.SizeLte('x', 10)</code>
results in <tt>{"x.10": {$exists: false}}</tt> *)
class function SizeLte(const AFieldName: String;
const ASize: Integer): TgoMongoFilter; overload; static;
public
{===================================
Bitwise
===================================}
(* Matches numeric or binary values in which a set of bit positions
@bold(all) have a value of 0.
Parameters:
AFieldName: the name of the field (left operand).
ABitMask: the set of bit positions (right operand).
Returns:
The filter.
Example: <code>TgoMongoFilter.BitsAllClear('x', 43)</code>
results in <tt>{x: {$bitsAllClear: 43}}</tt>
See https://docs.mongodb.org/manual/reference/operator/query/bitsAllClear/#op._S_bitsAllClear *)
class function BitsAllClear(const AFieldName: String;
const ABitMask: UInt64): TgoMongoFilter; static;