Cosmos DB alter collection
I am pretty new to Azure so this question might sound a little silly to some, apologies for that! Actually, I have a requirement where I need to alter the structure of an existing cosmos db collection to fit in one additional property. How can I do that with a Stored Procedure? Now,my scenario is somewhat like I have an existing collection which has approximately around 60 documents and the same collection is present in other environments also. I need to add a single property to the collection structure which should ideally be an one time activity.
I have checked Adding a new property to Cosmos DB but unlike this, my requirement is not to update the collection through code(C#), instead it is through a SP like I said. Now, since we can't use anything apart from SELECT query with Cosmos DB, how do I fit in an ALTER document functionality in the below code snippet?
function updateDocument(documentName){
var collection = getContext().getCollection();
var response = getContext().getResponse();
collection.queryDocuments(
// ALTER document code goes here
);
}
javascript asp.net azure azure-cosmosdb
add a comment |
I am pretty new to Azure so this question might sound a little silly to some, apologies for that! Actually, I have a requirement where I need to alter the structure of an existing cosmos db collection to fit in one additional property. How can I do that with a Stored Procedure? Now,my scenario is somewhat like I have an existing collection which has approximately around 60 documents and the same collection is present in other environments also. I need to add a single property to the collection structure which should ideally be an one time activity.
I have checked Adding a new property to Cosmos DB but unlike this, my requirement is not to update the collection through code(C#), instead it is through a SP like I said. Now, since we can't use anything apart from SELECT query with Cosmos DB, how do I fit in an ALTER document functionality in the below code snippet?
function updateDocument(documentName){
var collection = getContext().getCollection();
var response = getContext().getResponse();
collection.queryDocuments(
// ALTER document code goes here
);
}
javascript asp.net azure azure-cosmosdb
why not from c#?
– Steve Drake
Nov 20 '18 at 12:01
Because it(updating an existing collection structure) is a one time change that I need to do
– Deblina
Nov 20 '18 at 12:39
@Deblina - Please see the answers posted: you cannot perform updates via Cosmos DB SQL.
– David Makogon
Nov 20 '18 at 16:05
yes @David I get it..I have updated my question to make my requirement more clear..please have a look
– Deblina
Nov 21 '18 at 4:54
Using c# is not a limiting factor, it depends on what you are use to coding with. You can knock up batch updates in a few minutes and then use things like the 'ActionBlock' to multithread it all up so you can update huge numbers in very little time (I up the RU before any large update). BUT, I think I should also learn to do this stuff in function :)
– Steve Drake
Nov 21 '18 at 9:08
add a comment |
I am pretty new to Azure so this question might sound a little silly to some, apologies for that! Actually, I have a requirement where I need to alter the structure of an existing cosmos db collection to fit in one additional property. How can I do that with a Stored Procedure? Now,my scenario is somewhat like I have an existing collection which has approximately around 60 documents and the same collection is present in other environments also. I need to add a single property to the collection structure which should ideally be an one time activity.
I have checked Adding a new property to Cosmos DB but unlike this, my requirement is not to update the collection through code(C#), instead it is through a SP like I said. Now, since we can't use anything apart from SELECT query with Cosmos DB, how do I fit in an ALTER document functionality in the below code snippet?
function updateDocument(documentName){
var collection = getContext().getCollection();
var response = getContext().getResponse();
collection.queryDocuments(
// ALTER document code goes here
);
}
javascript asp.net azure azure-cosmosdb
I am pretty new to Azure so this question might sound a little silly to some, apologies for that! Actually, I have a requirement where I need to alter the structure of an existing cosmos db collection to fit in one additional property. How can I do that with a Stored Procedure? Now,my scenario is somewhat like I have an existing collection which has approximately around 60 documents and the same collection is present in other environments also. I need to add a single property to the collection structure which should ideally be an one time activity.
I have checked Adding a new property to Cosmos DB but unlike this, my requirement is not to update the collection through code(C#), instead it is through a SP like I said. Now, since we can't use anything apart from SELECT query with Cosmos DB, how do I fit in an ALTER document functionality in the below code snippet?
function updateDocument(documentName){
var collection = getContext().getCollection();
var response = getContext().getResponse();
collection.queryDocuments(
// ALTER document code goes here
);
}
javascript asp.net azure azure-cosmosdb
javascript asp.net azure azure-cosmosdb
edited Jan 27 at 21:22
marc_s
579k12911171263
579k12911171263
asked Nov 20 '18 at 11:38
Deblina Deblina
84
84
why not from c#?
– Steve Drake
Nov 20 '18 at 12:01
Because it(updating an existing collection structure) is a one time change that I need to do
– Deblina
Nov 20 '18 at 12:39
@Deblina - Please see the answers posted: you cannot perform updates via Cosmos DB SQL.
– David Makogon
Nov 20 '18 at 16:05
yes @David I get it..I have updated my question to make my requirement more clear..please have a look
– Deblina
Nov 21 '18 at 4:54
Using c# is not a limiting factor, it depends on what you are use to coding with. You can knock up batch updates in a few minutes and then use things like the 'ActionBlock' to multithread it all up so you can update huge numbers in very little time (I up the RU before any large update). BUT, I think I should also learn to do this stuff in function :)
– Steve Drake
Nov 21 '18 at 9:08
add a comment |
why not from c#?
– Steve Drake
Nov 20 '18 at 12:01
Because it(updating an existing collection structure) is a one time change that I need to do
– Deblina
Nov 20 '18 at 12:39
@Deblina - Please see the answers posted: you cannot perform updates via Cosmos DB SQL.
– David Makogon
Nov 20 '18 at 16:05
yes @David I get it..I have updated my question to make my requirement more clear..please have a look
– Deblina
Nov 21 '18 at 4:54
Using c# is not a limiting factor, it depends on what you are use to coding with. You can knock up batch updates in a few minutes and then use things like the 'ActionBlock' to multithread it all up so you can update huge numbers in very little time (I up the RU before any large update). BUT, I think I should also learn to do this stuff in function :)
– Steve Drake
Nov 21 '18 at 9:08
why not from c#?
– Steve Drake
Nov 20 '18 at 12:01
why not from c#?
– Steve Drake
Nov 20 '18 at 12:01
Because it(updating an existing collection structure) is a one time change that I need to do
– Deblina
Nov 20 '18 at 12:39
Because it(updating an existing collection structure) is a one time change that I need to do
– Deblina
Nov 20 '18 at 12:39
@Deblina - Please see the answers posted: you cannot perform updates via Cosmos DB SQL.
– David Makogon
Nov 20 '18 at 16:05
@Deblina - Please see the answers posted: you cannot perform updates via Cosmos DB SQL.
– David Makogon
Nov 20 '18 at 16:05
yes @David I get it..I have updated my question to make my requirement more clear..please have a look
– Deblina
Nov 21 '18 at 4:54
yes @David I get it..I have updated my question to make my requirement more clear..please have a look
– Deblina
Nov 21 '18 at 4:54
Using c# is not a limiting factor, it depends on what you are use to coding with. You can knock up batch updates in a few minutes and then use things like the 'ActionBlock' to multithread it all up so you can update huge numbers in very little time (I up the RU before any large update). BUT, I think I should also learn to do this stuff in function :)
– Steve Drake
Nov 21 '18 at 9:08
Using c# is not a limiting factor, it depends on what you are use to coding with. You can knock up batch updates in a few minutes and then use things like the 'ActionBlock' to multithread it all up so you can update huge numbers in very little time (I up the RU before any large update). BUT, I think I should also learn to do this stuff in function :)
– Steve Drake
Nov 21 '18 at 9:08
add a comment |
2 Answers
2
active
oldest
votes
Cosmos DB is a schema-less NoSQL database. Each document is completely independent from each other and it doesn't require you to change anything in order to add a new property. You can go straight to the portal and do it or programmatically though an SDK or a stored procedure.
SQL queries in Cosmos DB cannot alter the documents in a collection. It can only be used for querying.
Stored procedures can change a document but it requires you to read the document first and then update it. Keep in mind that they can be executed against a single logical partition.
I would highly suggest you read more about CosmosDB because it sounds like you don't fully understand what it is.
You can start here: https://docs.microsoft.com/en-us/azure/cosmos-db/sql-api-get-started
with stored procedures how can I update a document? I have I have updated my question to make my requirement more clear..please have a look
– Deblina
Nov 21 '18 at 5:00
@Deblina There are multiple examples that explain exactly how you can do that. The CosmsoDB stored proc repo is full of them.
– Nick Chapsas
Nov 21 '18 at 8:02
add a comment |
First off: There is no enforced schema, either at the document level or at the collection level. Store whatever document properties you want.
As for updating documents: the Core (SQL) API only provides querying via SQL (e.g. SELECT
statements). For creates, updates, or deletes, you must use API / SDK calls.
But @David, what if I don't want to use API / SDK calls? My scenario is like I have an existing collection which has approximately around 60 documents and the same collection is present in other environments also. I need to add a single property to the collection structure which should ideally be an one time activity, right?
– Deblina
Nov 21 '18 at 5:04
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53392204%2fcosmos-db-alter-collection%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
Cosmos DB is a schema-less NoSQL database. Each document is completely independent from each other and it doesn't require you to change anything in order to add a new property. You can go straight to the portal and do it or programmatically though an SDK or a stored procedure.
SQL queries in Cosmos DB cannot alter the documents in a collection. It can only be used for querying.
Stored procedures can change a document but it requires you to read the document first and then update it. Keep in mind that they can be executed against a single logical partition.
I would highly suggest you read more about CosmosDB because it sounds like you don't fully understand what it is.
You can start here: https://docs.microsoft.com/en-us/azure/cosmos-db/sql-api-get-started
with stored procedures how can I update a document? I have I have updated my question to make my requirement more clear..please have a look
– Deblina
Nov 21 '18 at 5:00
@Deblina There are multiple examples that explain exactly how you can do that. The CosmsoDB stored proc repo is full of them.
– Nick Chapsas
Nov 21 '18 at 8:02
add a comment |
Cosmos DB is a schema-less NoSQL database. Each document is completely independent from each other and it doesn't require you to change anything in order to add a new property. You can go straight to the portal and do it or programmatically though an SDK or a stored procedure.
SQL queries in Cosmos DB cannot alter the documents in a collection. It can only be used for querying.
Stored procedures can change a document but it requires you to read the document first and then update it. Keep in mind that they can be executed against a single logical partition.
I would highly suggest you read more about CosmosDB because it sounds like you don't fully understand what it is.
You can start here: https://docs.microsoft.com/en-us/azure/cosmos-db/sql-api-get-started
with stored procedures how can I update a document? I have I have updated my question to make my requirement more clear..please have a look
– Deblina
Nov 21 '18 at 5:00
@Deblina There are multiple examples that explain exactly how you can do that. The CosmsoDB stored proc repo is full of them.
– Nick Chapsas
Nov 21 '18 at 8:02
add a comment |
Cosmos DB is a schema-less NoSQL database. Each document is completely independent from each other and it doesn't require you to change anything in order to add a new property. You can go straight to the portal and do it or programmatically though an SDK or a stored procedure.
SQL queries in Cosmos DB cannot alter the documents in a collection. It can only be used for querying.
Stored procedures can change a document but it requires you to read the document first and then update it. Keep in mind that they can be executed against a single logical partition.
I would highly suggest you read more about CosmosDB because it sounds like you don't fully understand what it is.
You can start here: https://docs.microsoft.com/en-us/azure/cosmos-db/sql-api-get-started
Cosmos DB is a schema-less NoSQL database. Each document is completely independent from each other and it doesn't require you to change anything in order to add a new property. You can go straight to the portal and do it or programmatically though an SDK or a stored procedure.
SQL queries in Cosmos DB cannot alter the documents in a collection. It can only be used for querying.
Stored procedures can change a document but it requires you to read the document first and then update it. Keep in mind that they can be executed against a single logical partition.
I would highly suggest you read more about CosmosDB because it sounds like you don't fully understand what it is.
You can start here: https://docs.microsoft.com/en-us/azure/cosmos-db/sql-api-get-started
answered Nov 20 '18 at 11:53
Nick ChapsasNick Chapsas
2,9861515
2,9861515
with stored procedures how can I update a document? I have I have updated my question to make my requirement more clear..please have a look
– Deblina
Nov 21 '18 at 5:00
@Deblina There are multiple examples that explain exactly how you can do that. The CosmsoDB stored proc repo is full of them.
– Nick Chapsas
Nov 21 '18 at 8:02
add a comment |
with stored procedures how can I update a document? I have I have updated my question to make my requirement more clear..please have a look
– Deblina
Nov 21 '18 at 5:00
@Deblina There are multiple examples that explain exactly how you can do that. The CosmsoDB stored proc repo is full of them.
– Nick Chapsas
Nov 21 '18 at 8:02
with stored procedures how can I update a document? I have I have updated my question to make my requirement more clear..please have a look
– Deblina
Nov 21 '18 at 5:00
with stored procedures how can I update a document? I have I have updated my question to make my requirement more clear..please have a look
– Deblina
Nov 21 '18 at 5:00
@Deblina There are multiple examples that explain exactly how you can do that. The CosmsoDB stored proc repo is full of them.
– Nick Chapsas
Nov 21 '18 at 8:02
@Deblina There are multiple examples that explain exactly how you can do that. The CosmsoDB stored proc repo is full of them.
– Nick Chapsas
Nov 21 '18 at 8:02
add a comment |
First off: There is no enforced schema, either at the document level or at the collection level. Store whatever document properties you want.
As for updating documents: the Core (SQL) API only provides querying via SQL (e.g. SELECT
statements). For creates, updates, or deletes, you must use API / SDK calls.
But @David, what if I don't want to use API / SDK calls? My scenario is like I have an existing collection which has approximately around 60 documents and the same collection is present in other environments also. I need to add a single property to the collection structure which should ideally be an one time activity, right?
– Deblina
Nov 21 '18 at 5:04
add a comment |
First off: There is no enforced schema, either at the document level or at the collection level. Store whatever document properties you want.
As for updating documents: the Core (SQL) API only provides querying via SQL (e.g. SELECT
statements). For creates, updates, or deletes, you must use API / SDK calls.
But @David, what if I don't want to use API / SDK calls? My scenario is like I have an existing collection which has approximately around 60 documents and the same collection is present in other environments also. I need to add a single property to the collection structure which should ideally be an one time activity, right?
– Deblina
Nov 21 '18 at 5:04
add a comment |
First off: There is no enforced schema, either at the document level or at the collection level. Store whatever document properties you want.
As for updating documents: the Core (SQL) API only provides querying via SQL (e.g. SELECT
statements). For creates, updates, or deletes, you must use API / SDK calls.
First off: There is no enforced schema, either at the document level or at the collection level. Store whatever document properties you want.
As for updating documents: the Core (SQL) API only provides querying via SQL (e.g. SELECT
statements). For creates, updates, or deletes, you must use API / SDK calls.
answered Nov 20 '18 at 11:53
David MakogonDavid Makogon
57.1k15108154
57.1k15108154
But @David, what if I don't want to use API / SDK calls? My scenario is like I have an existing collection which has approximately around 60 documents and the same collection is present in other environments also. I need to add a single property to the collection structure which should ideally be an one time activity, right?
– Deblina
Nov 21 '18 at 5:04
add a comment |
But @David, what if I don't want to use API / SDK calls? My scenario is like I have an existing collection which has approximately around 60 documents and the same collection is present in other environments also. I need to add a single property to the collection structure which should ideally be an one time activity, right?
– Deblina
Nov 21 '18 at 5:04
But @David, what if I don't want to use API / SDK calls? My scenario is like I have an existing collection which has approximately around 60 documents and the same collection is present in other environments also. I need to add a single property to the collection structure which should ideally be an one time activity, right?
– Deblina
Nov 21 '18 at 5:04
But @David, what if I don't want to use API / SDK calls? My scenario is like I have an existing collection which has approximately around 60 documents and the same collection is present in other environments also. I need to add a single property to the collection structure which should ideally be an one time activity, right?
– Deblina
Nov 21 '18 at 5:04
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53392204%2fcosmos-db-alter-collection%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
why not from c#?
– Steve Drake
Nov 20 '18 at 12:01
Because it(updating an existing collection structure) is a one time change that I need to do
– Deblina
Nov 20 '18 at 12:39
@Deblina - Please see the answers posted: you cannot perform updates via Cosmos DB SQL.
– David Makogon
Nov 20 '18 at 16:05
yes @David I get it..I have updated my question to make my requirement more clear..please have a look
– Deblina
Nov 21 '18 at 4:54
Using c# is not a limiting factor, it depends on what you are use to coding with. You can knock up batch updates in a few minutes and then use things like the 'ActionBlock' to multithread it all up so you can update huge numbers in very little time (I up the RU before any large update). BUT, I think I should also learn to do this stuff in function :)
– Steve Drake
Nov 21 '18 at 9:08