Update one field in All Documents in Couchbase using .Net SDK 3.1

Problem: I am trying to built a utility project using .net sdk to update a specific field in all my couchbase documents of a specific doctype. i dont want to upsert but instead i want to update. is there any function in .net sdk which i can use to update the specific field.

Note: I dont want to use N1QL query since im updating the time field in all the documents which by query is not giving the precision i want which is upto micro seconds. for example: i want to store the time value in “2020-07-02T20:30:00.3966933Z” but using N1QL query function STR_TO_UTC it gives me “2020-07-02T20:30:00.396Z”

Sample Document:
“SampleDoc”: {

    "departureTime": "2020-07-02T15:00:00",
    "destination": "DEN",
    "docType": "TEST-DOC",
    "flightNumber": 1234,
    "lastUpdatedOn": "2020-07-02T20:30:00.3966933Z-05:00",
    "origin": "FCA",

“id”: “1234+FCA”

My Solution:

  public async Task<dynamic> UpdateToUtcTime()
        var collection = _bucket.DefaultCollection();
        var queryString = $"SELECT * FROM `{this._bucket.Name}` WHERE docType = 'TEST-DOC' AND DATE_TRUNC_STR(departureTime, 'day')" +
                    $" = '2020-07-03T00:00:00'";

        var queryResult = await _cluster.QueryAsync<MyResponse>(queryString, new Couchbase.Query.QueryOptions()).ConfigureAwait(false);

        int i = 0;

        await foreach (var record in queryResult.Rows)
            var convertToUtcTime = record.SampleDoc.LastUpdatedOn.ToUniversalTime();

            record.SampleDoc.LastUpdatedOn = convertToUtcTime;

            var id = record.SampleDoc.Id;
            var upsertResult = await collection.UpsertAsync(id, record.SampleDoc).ConfigureAwait(false);

        return null;

Please suggest me what can be done in order to avoid upserting and update only the field required to update. Using this code. i have almost 2000 records for a specific day and in total almost 1 million records. it is taking 60 seconds with this approach for 2000 records. if i need to run for all the records i need another clean approach on how to update all the documents

I’d suggest checking out sub-document operations: https://docs.couchbase.com/dotnet-sdk/current/howtos/subdocument-operations.html

For your case, look at the Mutating: https://docs.couchbase.com/dotnet-sdk/current/howtos/subdocument-operations.html#mutating

Something like:

await _collection.MutateInAsync(id, specs =>
    specs.Upsert("SampleDoc.LastUpdatedOn", convertToUtcTime)

And when you do this, you might also be able to ditch SELECT * for SELECT META().id, which should also speed up the query time.