Skip to content

Commit c2aae95

Browse files
authored
chore: bump version to 0.7.3 (#138)
1 parent bafe2d4 commit c2aae95

3 files changed

Lines changed: 89 additions & 6 deletions

File tree

README.md

Lines changed: 86 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,7 @@ The main difference between Partial update and Patch is that:
342342
```
343343

344344

345+
345346
### Cross-partition queries
346347

347348
```java
@@ -360,6 +361,8 @@ The main difference between Partial update and Patch is that:
360361
// !! not supported for mongodb !!
361362
```
362363

364+
365+
363366
### Raw SQL queries
364367

365368
```java
@@ -399,7 +402,9 @@ The main difference between Partial update and Patch is that:
399402
// !! not supported for mongodb !!
400403
```
401404

402-
### join queries
405+
406+
407+
### Join queries
403408

404409
```java
405410
var cond = Condition.filter(
@@ -454,9 +459,87 @@ var cosmos = new CosmosBuilder().withDatabaseType("cosmosdb")
454459

455460
```
456461

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.
457538

458539

459540
## Reference
460541

461-
This library is built based on the official Azure Cosmos DB Java SDK v4.
462-
https://learn.microsoft.com/en-us/azure/cosmos-db/nosql/sdk-java-v4
542+
This library is built based on the official Azure Cosmos DB Java SDK v4, and the offical MongoDB Java SDK
543+
544+
* https://learn.microsoft.com/en-us/azure/cosmos-db/nosql/sdk-java-v4
545+
* https://www.mongodb.com/docs/drivers/java/sync/current/

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<groupId>com.github.thunderz99</groupId>
55
<artifactId>java-cosmos</artifactId>
66
<packaging>jar</packaging>
7-
<version>0.7.2.1.RC4</version>
7+
<version>0.7.3</version>
88
<name>${project.groupId}:${project.artifactId}$</name>
99
<description>A lightweight Azure CosmosDB client for Java</description>
1010
<url>https://github.com/thunderz99/java-cosmos</url>

src/main/java/io/github/thunderz99/cosmos/condition/SubConditionType.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ public class SubConditionType {
2929
* db.Families.find({
3030
* "children": {
3131
* "$elemMatch": {
32-
* "age": { "$gt": 10 },
33-
* "sex": { "$eq": "female" }
32+
* "grade": { "$gt": 5 },
33+
* "gender": { "$eq": "female" }
3434
* }
3535
* }
3636
* })

0 commit comments

Comments
 (0)