nosql - Couchbase 更新查询划分

标签 nosql couchbase n1ql

我正在尝试使用沙发底座上的 UPDATE 查询语句来更新文档。 前任) 更新用户 SET cityIndex = 1 where Users.city= "NewYork";

数据太多,我想将 3,000 分成 4,000,然后进行 UPDATE。我该如何进行? 有主索引。

最佳答案

vsr 提到的事件函数方法也非常简单(7 行无注释),您可以将它作为一次性工具运行,从 Everything 部署它。请注意,不需要任何索引即可工作。

// To run configure the settings for this Function, UpdateAllCityIndex, as follows:
//
// Version 7.0+
//   "Listen to Location"
//     bulk.data.yourcollection
//   "Eventing Storage"
//     rr100.eventing.metadata
//   Binding(s)
//    1. "binding type", "alias name...", "bucket.scope.collection", "Access"
// ---------------------------------------------------------------------------
//       "bucket alias", "src_col",       "bulk.data.Users",         "read and write"
//
// Version 6.X
//   "Source Bucket"
//     yourbucket
//   "MetaData Bucket"
//     metadata
//   Binding(s)
//    1. "binding type", "alias name...", "bucket",     "Access"
// ---------------------------------------------------------------------------
//       "bucket alias", "src_col",       "Users",   "read and write"
//
// For more performance set the workers to the number of physical cores

function OnUpdate(doc, meta) {
    // only process documents with the city field
    if (!doc.city) return;
    
    // only update New York if cityIndex isn't already 1 or does not exist
    if (  doc.city === "NewYork" && (!doc.cityIndex || doc.cityIndex !== 1 )) {
        doc.cityIndex = 1;
        // write back the updated doc via the alias
        src_col[meta.id] = doc;
    }
}

关于nosql - Couchbase 更新查询划分,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70149707/

相关文章:

java - Spring & Couchbase - 如何通过代码创建索引

couchbase - 如何删除 couchbase 中没有子文档的文档?

design-patterns - 将存储库模式与文档数据库一起使用是否有意义?

java - 使用 Objectify 查询 2 个实体

java - Couchbase SDK 2 : bulk read operations , 如何故障转移到副本

node.js - S3 和 Couchbase - 如何从 Amazon 获取文件并存储它?

mysql - 不更新数据库(仅读/写)

database - noSql 相对于 newSql 的优势

沙发底座 N1QL : How to aggregate and join from the same bucket with an array of keys

couchbase - N1QL 查询不适用于一个实例,但适用于其他实例