Scan Consistency Using the .NET SDK with Couchbase Server

    +
    You can balance performance against consistency in N1QL queries via the Couchbase .NET client and the AtPlus option.

    Setting a Scan Consistency, lets you choose between NotBounded (the default), for sharpest performance; RequestPlus, for strongest consistency; and AtPlus, for a good balance between increased performance and completeness of results.

    In order to use at_plus, you’ll need to make sure that you explicitly set UseEnhancedDurability to true when setting up your ClientConfiguration:

    config.BucketConfigs = new Dictionary<string, BucketConfiguration> {
        {
            "travel-sample", new BucketConfiguration
            {
                UseEnhancedDurability = true
            }
        }
    };

    In the example below, the N1QL query will wait only for the new document to be indexed.

    Setting at_plus consistency
    private static void AtPlusExample()
    {
        Console.WriteLine("========= AtPlus");
    
        // get the current count
        var getResult = _bucket.Query<dynamic>("SELECT COUNT(1) as airportCount FROM `travel-sample` WHERE type='airport'")
                .Rows.First();
        Console.WriteLine($"Initial count: {result1.airportCount}");
    
        // insert a new airport
        var doc = new Document<dynamic>
        {
            Id = "ScanConsistency::airport::" + _random.Next(10000),
            Content = new
            {
                type = "airport"
            }
        };
        var insertResult = _bucket.Insert(doc);
    
        // get the count again, creating mutation state from insert result
        var state = MutationState.From(insertResult.Document);
        var request = new QueryRequest("SELECT COUNT(1) as airportCount FROM `travel-sample` WHERE type='airport'")
            .ConsistentWith(state);
        var queryResult = _bucket.Query<dynamic>(t).Rows.First();
        Console.WriteLine($"Count after insert with AtPlus: {result2.airportCount}");
    }