Cosmos DB alter collection












0














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.qeuryDocuments(

// ALTER document code goes here

);
}









share|improve this question
























  • 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


















0














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.qeuryDocuments(

// ALTER document code goes here

);
}









share|improve this question
























  • 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
















0












0








0







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.qeuryDocuments(

// ALTER document code goes here

);
}









share|improve this question















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.qeuryDocuments(

// ALTER document code goes here

);
}






javascript asp.net azure azure-cosmosdb






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 21 '18 at 5:06

























asked Nov 20 '18 at 11:38









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




















  • 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














2 Answers
2






active

oldest

votes


















0














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






share|improve this answer





















  • 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



















0














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.






share|improve this answer





















  • 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











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
});


}
});














draft saved

draft discarded


















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









0














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






share|improve this answer





















  • 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
















0














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






share|improve this answer





















  • 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














0












0








0






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






share|improve this answer












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







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 20 '18 at 11:53









Nick Chapsas

2,5761314




2,5761314












  • 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










  • @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













0














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.






share|improve this answer





















  • 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
















0














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.






share|improve this answer





















  • 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














0












0








0






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.






share|improve this answer












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.







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 20 '18 at 11:53









David Makogon

56.1k15104150




56.1k15104150












  • 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




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


















draft saved

draft discarded




















































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.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


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




draft saved


draft discarded














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





















































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







Popular posts from this blog

"Incorrect syntax near the keyword 'ON'. (on update cascade, on delete cascade,)

Alcedinidae

RAC Tourist Trophy