Skip to content

Commit 151291e

Browse files
authored
INTMDB-211: Added shard keys properties to Managed Namespace in global configurat… (#253)
1 parent 33a5da3 commit 151291e

File tree

2 files changed

+27
-14
lines changed

2 files changed

+27
-14
lines changed

mongodbatlas/global_clusters.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,11 @@ type GlobalCluster struct {
4848

4949
// ManagedNamespace represents the information about managed namespace configuration.
5050
type ManagedNamespace struct {
51-
Db string `json:"db"` //nolint:stylecheck // not changing this as is a breaking change
52-
Collection string `json:"collection"`
53-
CustomShardKey string `json:"customShardKey,omitempty"`
51+
Db string `json:"db"` //nolint:stylecheck // not changing this as is a breaking change
52+
Collection string `json:"collection"`
53+
CustomShardKey string `json:"customShardKey,omitempty"`
54+
IsCustomShardKeyHashed *bool `json:"isCustomShardKeyHashed,omitempty"` // Flag that specifies whether the custom shard key for the collection is hashed.
55+
IsShardKeyUnique *bool `json:"isShardKeyUnique,omitempty"` // Flag that specifies whether the underlying index enforces a unique constraint.
5456
}
5557

5658
// CustomZoneMappingsRequest represents the request related to add custom zone mappings to a global cluster.

mongodbatlas/global_clusters_test.go

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"testing"
2222

2323
"github.com/go-test/deep"
24+
"github.com/openlyinc/pointy"
2425
)
2526

2627
func TestGlobalClusters_Get(t *testing.T) {
@@ -50,7 +51,9 @@ func TestGlobalClusters_Get(t *testing.T) {
5051
"managedNamespaces" : [ {
5152
"collection" : "zips",
5253
"customShardKey" : "city",
53-
"db" : "mydata"
54+
"db" : "mydata",
55+
"isCustomShardKeyHashed" : true,
56+
"isShardKeyUnique" : true
5457
},{
5558
"collection" : "stores",
5659
"customShardKey" : "store_number",
@@ -81,9 +84,11 @@ func TestGlobalClusters_Get(t *testing.T) {
8184
},
8285
ManagedNamespaces: []ManagedNamespace{
8386
{
84-
Collection: "zips",
85-
CustomShardKey: "city",
86-
Db: "mydata",
87+
Collection: "zips",
88+
CustomShardKey: "city",
89+
Db: "mydata",
90+
IsCustomShardKeyHashed: pointy.Bool(true),
91+
IsShardKeyUnique: pointy.Bool(true),
8792
}, {
8893
Collection: "stores",
8994
CustomShardKey: "store_number",
@@ -105,16 +110,20 @@ func TestGlobalClusters_AddManagedNamespace(t *testing.T) {
105110
clusterName := "appData"
106111

107112
createRequest := &ManagedNamespace{
108-
Db: "mydata",
109-
Collection: "publishers",
110-
CustomShardKey: "city",
113+
Db: "mydata",
114+
Collection: "publishers",
115+
CustomShardKey: "city",
116+
IsCustomShardKeyHashed: pointy.Bool(true),
117+
IsShardKeyUnique: pointy.Bool(true),
111118
}
112119

113120
mux.HandleFunc(fmt.Sprintf("/api/atlas/v1.0/groups/%s/clusters/%s/globalWrites/managedNamespaces", groupID, clusterName), func(w http.ResponseWriter, r *http.Request) {
114121
expectedRequest := map[string]interface{}{
115-
"db": "mydata",
116-
"collection": "publishers",
117-
"customShardKey": "city",
122+
"db": "mydata",
123+
"collection": "publishers",
124+
"customShardKey": "city",
125+
"isCustomShardKeyHashed": true,
126+
"isShardKeyUnique": true,
118127
}
119128

120129
jsonBlob := `
@@ -136,7 +145,9 @@ func TestGlobalClusters_AddManagedNamespace(t *testing.T) {
136145
"managedNamespaces" : [ {
137146
"collection" : "publishers",
138147
"customShardKey" : "city",
139-
"db" : "mydata"
148+
"db" : "mydata",
149+
"isCustomShardKeyHashed" : true,
150+
"isShardKeyUnique" : true
140151
},{
141152
"collection" : "stores",
142153
"customShardKey" : "store_number",

0 commit comments

Comments
 (0)