This repository was archived by the owner on Aug 29, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove partition key and add and query support (#37)
* add and query support * remove partitionkey from repository paramter * complete test * split test into partition and non-partition * enable cross region when partition key value not specified * add query partitioned collection readme * add test find by ID field name for partitioned collection * improve readme
- Loading branch information
Showing
24 changed files
with
591 additions
and
320 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
### How to Query Partitioned DocumentDB Collection | ||
|
||
With DocumentDB, you can configure [partition key](https://docs.microsoft.com/en-us/azure/cosmos-db/partition-data) for your collection. | ||
|
||
Below is an example about how to query partitioned collection with this spring data module. | ||
|
||
#### Example | ||
|
||
Given a document entity structure: | ||
``` | ||
@Document | ||
@Data | ||
@AllArgsConstructor | ||
public class Address { | ||
@Id | ||
String postalCode; | ||
String street; | ||
@PartitionKey | ||
String city; | ||
} | ||
``` | ||
|
||
Write the repository interface: | ||
``` | ||
@Repository | ||
public interface AddressRepository extends DocumentDbRepository<Address, String> { | ||
// Add query methods here, refer to below | ||
} | ||
``` | ||
|
||
Query by field name: | ||
``` | ||
List<Address> findByCity(String city); | ||
``` | ||
|
||
Delete by field name: | ||
``` | ||
void deleteByStreet(String street); | ||
``` | ||
|
||
For `Partitioned collection`, if you want to query records by `findById(id)`, exception will be thrown. | ||
``` | ||
// Incorrect for partitioned collection, exception will be thrown | ||
Address result = repository.findById(id); // Caution: Works for non-partitioned collection | ||
``` | ||
|
||
Instead, you can query records by ID field name with custom query. | ||
``` | ||
// Correct, postalCode is the ID field in Address domain | ||
@Repository | ||
public interface AddressRepository extends DocumentDbRepository<Address, String> { | ||
List<Address> findByPostalCode(String postalCode); | ||
} | ||
// Query | ||
List<Address> result = repository.findByPostalCode(postalCode); | ||
``` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.