I have a desire to add a property with a default value to the set of documents that I get with a SELECT query if they do not contain a value.
I thought about this in two parts:
I would like to find all articles where article.details.x does not exist.
I was hoping that this EXEC command could be supported through the Azure Portal, so I did not need to create a migration tool to run this command once, but I could not find this option on the portal. Is it possible?
Azure Document DB Studio . . .
:
function updateArticlesDetailsX() { var collection = getContext().getCollection(); var collectionLink = collection.getSelfLink(); var response = getContext().getResponse(); var docCount = 0; var counter = 0; tryQueryAndUpdate(); function tryQueryAndUpdate(continuation) { var query = { query: "select * from root r where IS_DEFINED(r.details.x) != true" }; var requestOptions = { continuation: continuation }; var isAccepted = collection .queryDocuments(collectionLink, query, requestOptions, function queryCallback(err, documents, responseOptions) { if (err) throw err; if (documents.length > 0) { // If at least one document is found, update it. docCount = documents.length; for (var i=0; i<docCount; i++){ tryUpdate(documents[i]); } response.setBody("Updated " + docCount + " documents"); } else if (responseOptions.continuation) { // Else if the query came back empty, but with a continuation token; // repeat the query w/ the token. tryQueryAndUpdate(responseOptions.continuation); } else { throw new Error("Document not found."); } }); if (!isAccepted) { throw new Error("The stored procedure timed out"); } } function tryUpdate(document) { //Optimistic concurrency control via HTTP ETag. var requestOptions = { etag: document._etag }; //Update statement goes here: document.details.x = "some new value"; var isAccepted = collection .replaceDocument(document._self, document, requestOptions, function replaceCallback(err, updatedDocument, responseOptions) { if (err) throw err; counter++; }); // If we hit execution bounds - throw an exception. if (!isAccepted) { throw new Error("The stored procedure timed out"); } } }
GitHub.
, .
DocumentDB . Script, . sproc, replaceDocument , . , , , DocumentDB sprocs 5 ( ). , , , sproc , , 5 . IS_DEFINED (collection.field.subfield)!= True (thanks @cnaegle) , , ( ), sproc , .
sproc, DocumentDB Data Migration. Excel, Script, . .
Source: https://habr.com/ru/post/1623983/More articles:ImageView scaling does not work - androidINVALID_REQUEST error in pull tasks - google-app-engineHow to license Google Play services correctly? - google-play-services.NET thread pool and execution context, class ExecutionContext - multithreadingHow to get Angular2 to work in the generated distribution folder? - javascriptSubtracting all elements of array A from all elements of B? - pythonGson: @Expose vs @SerializedName - javaSending SMS from contacts - iosOsgi не будет соответствовать внутреннему коду внутри пакета - unresolved-externalInterrupt handling during a phone call - “start” works, but “end” is not - iosAll Articles