-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
72 additions
and
8 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,15 @@ | ||
# adaptTo() Live Server - Schema Creation for Cosmos DB (MS Azure) | ||
|
||
As stated in the [CosmosDB documentation][cosmosdb-limitations], it's not possible to create a unique index after a collection was created: | ||
|
||
> Azure Cosmos DB API for SQL or MongoDB accounts that create unique index after the container is created aren't supported for continuous backup. Only containers that create unique index as a part of the initial container creation are supported. For MongoDB accounts, you create unique index using [extension commands][cosmosdb-extension-commands]. | ||
The collection `qa-entries` requires a compound unique partial index to ensure the `entryIndex` numbers are numbered continuously for each talk, generating a number of QA entry numbers for each talk. This works via Mongoose schema definition of a native MongoDB instance, but not for CosmosDB with continuous backup. | ||
|
||
The solution is to drop the collection `qa-entries` after creating the collections via Mongoose on server setup, and then recreate it via MongoDB shell using this script: | ||
|
||
[qa-entries.txt](qa-entries.txt) | ||
|
||
|
||
[cosmosdb-limitations]: https://learn.microsoft.com/en-us/azure/cosmos-db/continuous-backup-restore-introduction#current-limitations | ||
[cosmosdb-extension-commands]: https://learn.microsoft.com/en-us/azure/cosmos-db/mongodb/custom-commands |
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,49 @@ | ||
use adaptto-live | ||
|
||
db["qa-entries"].drop() | ||
|
||
db.runCommand({ | ||
customAction: "CreateCollection", | ||
collection: "qa-entries", | ||
indexes: [ | ||
{ | ||
name: "_id_", | ||
key: { "_id": 1 }, | ||
unique: true | ||
}, | ||
{ | ||
name: "talkId_1", | ||
key: { "talkId": 1 } | ||
}, | ||
{ | ||
name: "date_1", | ||
key: { "date": 1 } | ||
}, | ||
{ | ||
name: "userid_1", | ||
key: { "userid": 1 } | ||
}, | ||
{ | ||
name: "entryIndex_1", | ||
key: { "entryIndex": 1 } | ||
}, | ||
{ | ||
name: "replyTo_1", | ||
key: { "replyTo": 1 } | ||
}, | ||
{ | ||
name: "userid_1_username_1", | ||
key: { "userid": 1, "username": 1 } | ||
}, | ||
{ | ||
name: "qaEntryId_1_userid_1", | ||
key: { "qaEntryId": 1, "userid": 1 } | ||
}, | ||
{ | ||
name: "talkId_1_entryIndex_1", | ||
key: { "talkId": 1, "entryIndex": -1 }, | ||
unique: true, | ||
partialFilterExpression: { "entryIndex": { "$gt": 0 } } | ||
} | ||
] | ||
}) |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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