Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Couchbase Update query divide

I am trying to update the document using the UPDATE query statement on the couchbase. EX) UPDATE Users SET cityIndex = 1 where Users.city= "NewYork";

There was so much data that I wanted to divide 3,000 to 4,000 and proceed with the UPDATE. How should I proceed? There is PRIMARY INDEX.

like image 773
Jingon Park Avatar asked Dec 10 '25 04:12

Jingon Park


1 Answers

The Eventing Function method that vsr alluded too is quite simple (7 lines sans comments) and you run it as a one-off point tool deploying it from Everything. Note there is no need for any index for this to work.

// 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;
    }
}
like image 161
Jon Strabala Avatar answered Dec 13 '25 06:12

Jon Strabala



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!