如何在 Cochbase 和节点 js 中批量插入不同的键

how to bulk insert with different key in Cochbase and node js

我想导入 MySQL 数据并进行一些更改。就像在 json 中加入和 json。 我可以一个一个地插入它。但这需要很多时间。 我正在通过以下代码执行此操作。这段代码在 for 循环中

config.bucket.insert('User|'+page._id, JSON.stringify(page), function(err, res) {

                    if (err) {
                     console.log('User|'+page._id+' operation failed  '+ err);
                      return;
                    }
                    console.log('User|'+page._id);

                });

所以,我需要。 如何在 Cochbase 和节点 js 中使用不同的键进行批量插入??

page._id 不同 key.I 插入时也需要它 json

我很确定这就是您要找的: https://github.com/couchbaselabs/devguide-examples/blob/master/nodejs/bulkES6.js

function bulkUpdateAsyncPattern(){
  return new Promise(
      (resolve, reject) => {

          var completed = 0;
          var runFlag = false;
          var startTime = process.hrtime();

          // Function for modify one document, during bulk loop.  Notice,
          // this is only in scope for bulkUpdateAsyncPattern
          function modifyOne() {

              // First Check if the bulk pattern loop is done
              if (completed >= totalDocs && !runFlag) {
                  runFlag = true;
                  var time = process.hrtime(startTime);
                  console.log("====");
                  console.log("  Bulk Pattern Processing Loop Took: " + parseInt((time[0] * 1000) +
                          (time[1] / 1000000)) + " ms for: " + getMultiArray.length +
                      " items");
                  resolve();
              } else {
                  if (completed <= totalDocs) {

                      // Modify One Document
                      bucket.mutateIn('test' + completed, 0, 0)
                      .counter('rev', 1, false)
                      .execute( function(err, res) {
                          if (err) console.log("  Error modifying:", err.message);

                          // This will fire WHEN and only WHEN a callback is received.
                          if (res) {
                              // Increment completed count
                              completed++;

                              // Recursive call to modify
                              modifyOne();
                          }
                      });
                  }
              }
          }
          // The loop that sets up a "buffer" of queued operations
          // This sets up a number of requests always in the buffer waiting to execute
          for (var i = 0; i < opsGroup; ++i) {
              modifyOne();
          }
      });
}