You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+86-3Lines changed: 86 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -342,6 +342,7 @@ The main difference between Partial update and Patch is that:
342
342
```
343
343
344
344
345
+
345
346
### Cross-partition queries
346
347
347
348
```java
@@ -360,6 +361,8 @@ The main difference between Partial update and Patch is that:
360
361
// !! not supported for mongodb !!
361
362
```
362
363
364
+
365
+
363
366
### Raw SQL queries
364
367
365
368
```java
@@ -399,7 +402,9 @@ The main difference between Partial update and Patch is that:
399
402
// !! not supported for mongodb !!
400
403
```
401
404
402
-
### join queries
405
+
406
+
407
+
### Join queries
403
408
404
409
```java
405
410
var cond =Condition.filter(
@@ -454,9 +459,87 @@ var cosmos = new CosmosBuilder().withDatabaseType("cosmosdb")
454
459
455
460
```
456
461
462
+
### $ELEM_MATCH queries in mongo to match fields in array type field
463
+
464
+
For cosmosdb, we can do a query like this using rawSql to find a child whose grade greater than 5 and gender is "female".
465
+
466
+
```
467
+
// the document, contains an array field named "children"
468
+
{
469
+
"_id": "WakefieldFamily",
470
+
"id": "WakefieldFamily",
471
+
"children": [
472
+
{
473
+
"familyName": "Merriam",
474
+
"givenName": "Jesse",
475
+
"gender": "female",
476
+
"grade": 1,
477
+
"pets": [
478
+
{
479
+
"givenName": "Goofy"
480
+
},
481
+
{
482
+
"givenName": "Shadow"
483
+
}
484
+
]
485
+
},
486
+
{
487
+
"familyName": "Miller",
488
+
"givenName": "Lisa",
489
+
"gender": "female",
490
+
"grade": 8
491
+
}
492
+
],
493
+
"address": {
494
+
"state": "NY",
495
+
"county": "Manhattan",
496
+
"city": "NY"
497
+
},
498
+
"_partition": "Families"
499
+
}
500
+
501
+
```
502
+
503
+
```
504
+
// Java code using rawSQL
505
+
var sql = """
506
+
SELECT * FROM c WHERE
507
+
EXISTS(SELECT VALUE children FROM children IN c["children"]
508
+
WHERE (children.grade > 5) AND (children.gender = "female")
509
+
)
510
+
""";
511
+
512
+
var cond = Condition.rawSql(sql);
513
+
var result = db.find("Collection1", cond);
514
+
515
+
```
516
+
517
+
We do not support rawSql in mongodb, so we introduce a $ELEM_MATCH filter to achieve this.
518
+
519
+
```
520
+
// the mongosh is:
521
+
db.Families.find({
522
+
"children": {
523
+
"$elemMatch": {
524
+
"grade": { "$gt": 5 },
525
+
"gender": { "$eq": "female" }
526
+
}
527
+
}
528
+
});
529
+
```
530
+
531
+
```
532
+
// Java code is:
533
+
var cond = Condition.filter("$ELEM_MATCH", Map.of("grade >", 5, "gender =" "female"));
534
+
var result = db.find("Collection1", cond);
535
+
```
536
+
537
+
At present, "$ELEM_MATCH" only works for mongodb. But we will consider support it for cosmosdb too, so that we do not need to use rawSql. And the same Java code will work for both database type.
457
538
458
539
459
540
## Reference
460
541
461
-
This library is built based on the official Azure Cosmos DB Java SDK v4.
0 commit comments