Using API to delete multiple rows

You can use the MultiDeleteRequest API and delete more than one row from a NoSQL table.

You can use MultiDeleteRequest to delete multiple rows from a table in an atomic operation. The key used may be partial but must contain all of the fields that are in the shard key. A range may be specified to delete a range of keys. As this operation can exceed the maximum amount of data that can be modified in a single operation, a continuation key can be used to continue the operation.

If a table's primary key is <YYYYMM, timestamp> and the its shard key is the YYYYMM, then all records that hit in the same month would be in same shard. It is possible to delete a range of timestamp values for a specific month using MultiDeleteRequest class.

See Oracle NoSQL Java SDK API Reference for more details on the various classes and methods.

Download the full code MultiDataOps.java from the examples here.
//Delete multiple rows from the table
private static void delMulRows(NoSQLHandle handle,int pinval) throws Exception {
   MapValue key = new MapValue().put("pin", 1234567);
   MultiDeleteRequest multiDelRequest = new MultiDeleteRequest()
          .setKey(key)
          .setTableName(tableName);

   MultiDeleteResult mRes = handle.multiDelete(multiDelRequest);
   System.out.println("MultiDelete result = " + mRes);
}

/*delete multiple rows using shard key*/
delMulRows(handle,1234567);

You can use borneo.MultiDeleteRequest class to perform multiple deletes in a single atomic operation.

See Oracle NoSQL Python SDK API Reference for more details on the various classes and methods.

Download the full code MultiDataOps.py from the examples here.
#delete multiple rows
def multirow_delete(handle,table_name,pinval):
   request = MultiDeleteRequest().set_table_name(table_name).set_key({'pin': pinval})
   result = handle.multi_delete(request)
)
/*delete multiple rows using shard key*/
multirow_delete(handle,'examplesAddress',1234567)

You can use MultiDelete method to delete multiple rows from a table in a single atomic operation.

See Oracle NoSQL Go SDK API Reference for more details on the various classes and methods.

Download the full code MultiDataOps.go from the examples here.
//delete multiple rows
func delMulRows(client *nosqldb.Client, err error, tableName string,pinval int)(){
   shardKey := &types.MapValue{}
   shardKey.Put("pin", pinval)
   multiDelReq := &nosqldb.MultiDeleteRequest{
		TableName: tableName,
		Key:       shardKey,
   }
   multiDelRes, err := client.MultiDelete(multiDelReq)
   if err != nil {
      fmt.Printf("failed to delete multiple rows: %v", err)
      return
   }
   fmt.Printf("MultiDelete result=%v\n", multiDelRes)
}
/*delete multiple rows using shard key*/
delMulRows(client, err,tableName,1234567)

You can delete multiple rows having the same shard key in a single atomic operation using the deleteRange method.

JavaScript: Download the full code MultiDataOps.js from the examples here.
//deletes multiple rows
async function mulRowDel(handle,pinval){
   try {
      /* Unconditional delete, should succeed.*/
      var result = await handle.deleteRange(TABLE_NAME, { pin: pinval });
      /* Expected output: delete succeeded*/
      console.log('delete ' + result.success ? 'succeeded' : 'failed');
   } catch(error) {
      console.error('  Error: ' + error.message);
   }
}
/*delete multiple rows using shard key*/
await mulRowDel(handle,1234567);
TypeScript: Download the full code MultiDataOps.ts from the examples here.
interface StreamInt {
   acct_Id: Integer;
   profile_name: String;
   account_expiry: TIMESTAMP;
   acct_data: JSON;
}
//deletes multiple rows
async function mulRowDel(handle: NoSQLClient,pinVal: Integer){
   try {
      /* Unconditional delete, should succeed.*/
      var result = await handle.deleteRange<StreamInt>(TABLE_NAME, { pin: pinval });
      /* Expected output: delete succeeded*/
      console.log('delete ' + result.success ? 'succeeded' : 'failed');
   } catch(error) {
      console.error('  Error: ' + error.message);
   }
}
/*delete multiple rows using shard key*/
await mulRowDel(handle,1234567);

You can delete multiple rows having the same shard key in a single atomic operation using DeleteRangeAsync method.

Download the full code MultiDataOps.cs from the examples here.
//delete multiple rows
private static async Task mulDelRows(NoSQLClient client,int pinval){
   var parKey = new MapValue {["pin"] = pinval};
   var options = new DeleteRangeOptions();
   do
   {
      var result = await client.DeleteRangeAsync(TableName,parKey,options);
      Console.WriteLine($"Deleted {result.DeletedCount} row(s)");
      options.ContinuationKey = result.ContinuationKey;
   } while(options.ContinuationKey != null);
}
/*delete multiple rows using shard key*/
await mulDelRows(client,1234567);