0
複数の列が類似している場合(posted_byとlocation)、is_approved = falseを反転させたいドキュメントがあります。上記のコードでDocumentDB:複数の列でリストを更新する際の問題
私は複数の重複する列を取得することができますクエリを記述することはできませんよ..
function Prop() {
var collection = getContext().getCollection();
var collectionLink = collection.getSelfLink();
var response = getContext().getResponse();
var counter = 0;
var responseBody = {
updated: 0,
continuation: true,
error: "",
log: ""
};
// Validate input.
getFullListOfPosts();
// Recursively queries for a document by id w/ support for continuation tokens.
// Calls findDuplicates(document) as soon as the query returns a document.
function getFullListOfPosts(continuation) {
var query = {
query: "select * from root r ORDER BY r.created.epoch DESC"
};
var requestOptions = {
continuation: continuation
};
var isAccepted = collection.queryDocuments(collectionLink, query, requestOptions, proccessFullListOfPosts);
// If we hit execution bounds - throw an exception.
if (!isAccepted) {
responseBody.log += "Query not accepted";
response.setBody(responseBody);
}
}
function proccessFullListOfPosts(err, documents, responseOptions) {
if (err) {
responseBody.error = err;
throw err;
}
if (documents.length > 0) {
// If documents are found, update them.
responseBody.log += "Found documents: " + documents.length;
findDuplicates(documents);
}
}
// Updates the supplied document according to the update object passed in to the sproc.
function findDuplicates(documents) {
if (documents.length > 0) {
responseBody.log += "Updating documents " + documents.length;
//for (var i = 0; i < documents.length; i++) {
var first = documents[0];
//The below query is not right. I want the above query to fetch all records with same posted_by and location and turn its is_approved to false
var query = 'select * from root r WHERE r.is_approved = true AND r.posted_by = "' + first.posted_by + '"';
var requestOptions = {
etag: first._etag
};
var isAccepted = collection.queryDocuments(collectionLink, query, requestOptions, identifyRecordsToDisable);
// Update the document. // If we hit execution bounds - throw an exception.
if (!isAccepted) {
responseBody.log += "Update not accepted";
response.setBody(responseBody);
}
} else {
getFullListOfPosts();
}
}
function identifyRecordsToDisable(err, documents, responseOptions) {
if (err) {
responseBody.error = err;
throw err;
}
if (documents.length > 0) {
// If documents are found, update them.
responseBody.log += "Found documents: " + documents.length;
for (var i = 0; i < documents.length; i++) {
var j = documents[i];
j.is_approved = false;
responseBody.log += "^Updated" + j.id + j.is_approved + ""
var requestOptions = {
etag: j._etag
};
var isAccepted = collection.replaceDocument(j._self, j, requestOptions, onReplaced);
responseBody.log += "*" + j.id + j.is_approved + "*"
}
findDuplicates(documents);
}
}
function onReplaced(err, updatedDocument, responseOptions) {
if (err) {
responseBody.error = err;
//throw err;
}
counter++;
response.setBody("Updated " + counter + " documents");
}
}
、関数「findDuplicates」で、私が通じI正しいクエリを記述することができませんすべての重複レコードを取得できます。
私はdistinct、group byを使ってみました。持っている。私は文書化してもそれらをサポートしていないと思う
さらに詳しい情報がある場合は、*あなたの質問を編集* - コメントに余分な内容を投稿しないでください。 –
サンプル文書を提供できますか?また、最初の文章は理解しにくいです。あなたは言い直し/訂正できますか? –