Support of Couchbase for .NET
CAST supports Couchbase via its com.castsoftware.nosqldotnet extension. Details about how this support is provided for .NET source code is discussed below.
Supported Client Libraries
Library |
Supported |
---|---|
Supported Operations
Operation | Library Version | Methods Supported |
---|---|---|
Create | 2.x | Couchbase.Cluster.OpenBucket Couchbase.Core.ICluster.OpenBucket Couchbase.Cluster.OpenBucketAsync Couchbase.Core.ICluster.OpenBucketAsync Couchbase.ClusterHelper.GetBucket Couchbase.ClusterHelper.GetBucketAsync Couchbase.Core.ClusterController.CreateBucket Couchbase.Core.IClusterController.CreateBucket Couchbase.Management.ClusterManager.CreateBucket Couchbase.Management.IClusterManager.CreateBucket Couchbase.Core.ClusterController.CreateBucketAsync Couchbase.Core.IClusterController.CreateBucketAsync Couchbase.Management.ClusterManager.CreateBucketAsync Couchbase.Management.IClusterManager.CreateBucketAsync |
Create | 3.x | Couchbase.IBucket.CollectionAsync Couchbase.Core.BucketBase.CollectionAsync Couchbase.KeyValue.IScope.CollectionAsync Couchbase.KeyValue.Scope.CollectionAsync Couchbase.IBucket.Collection Couchbase.Core.BucketBase.Collection Couchbase.KeyValue.IScope.Collection Couchbase.KeyValue.Scope.Collection Couchbase.IBucket.DefaultCollection Couchbase.Core.BucketBase.DefaultCollection Couchbase.IBucket.DefaultCollectionAsync Couchbase.Core.BucketBase.DefaultCollectionAsync |
Insert | 2.x | Couchbase.CouchbaseBucket.Insert Couchbase.MemcachedBucket.Insert Couchbase.Core.IBucket.Insert Couchbase.CouchbaseBucket.InsertAsync Couchbase.MemcachedBucket.InsertAsync Couchbase.Core.IBucket.InsertAsync |
Insert | 3.x | Couchbase.KeyValue.CollectionExtensions.InsertAsync Couchbase.KeyValue.CouchbaseCollection.InsertAsync Couchbase.KeyValue.ICouchbaseCollection.InsertAsync |
Update | 2.x | Couchbase.CouchbaseBucket.Replace Couchbase.MemcachedBucket.Replace Couchbase.Core.IBucket.Replace Couchbase.CouchbaseBucket.Upsert Couchbase.MemcachedBucket.Upsert Couchbase.Core.IBucket.Upsert Couchbase.CouchbaseBucket.Append Couchbase.MemcachedBucket.Append Couchbase.Core.IBucket.Append Couchbase.CouchbaseBucket.Prepend Couchbase.MemcachedBucket.Prepend Couchbase.Core.IBucket.Prepend Couchbase.CouchbaseBucket.Increment Couchbase.MemcachedBucket.Increment Couchbase.Core.IBucket.Increment Couchbase.CouchbaseBucket.Decrement Couchbase.MemcachedBucket.Decrement Couchbase.Core.IBucket.Decrement Couchbase.CouchbaseBucket.MutateIn Couchbase.MemcachedBucket.MutateIn Couchbase.Core.IBucket.MutateIn Couchbase.CouchbaseBucket.ReplaceAsync Couchbase.MemcachedBucket.ReplaceAsync Couchbase.Core.IBucket.ReplaceAsync Couchbase.CouchbaseBucket.UpsertAsync Couchbase.MemcachedBucket.UpsertAsync Couchbase.Core.IBucket.UpsertAsync Couchbase.CouchbaseBucket.AppendAsync Couchbase.MemcachedBucket.AppendAsync Couchbase.Core.IBucket.AppendAsync Couchbase.CouchbaseBucket.PrependAsync Couchbase.MemcachedBucket.PrependAsync Couchbase.Core.IBucket.PrependAsync Couchbase.CouchbaseBucket.IncrementAsync Couchbase.MemcachedBucket.IncrementAsync Couchbase.Core.IBucket.IncrementAsync Couchbase.CouchbaseBucket.DecrementAsync Couchbase.MemcachedBucket.DecrementAsync Couchbase.Core.IBucket.DecrementAsync |
Update | 3.x | Couchbase.KeyValue.CollectionExtensions.ReplaceAsync Couchbase.KeyValue.CouchbaseCollection.ReplaceAsync Couchbase.KeyValue.ICouchbaseCollection.ReplaceAsync Couchbase.KeyValue.CollectionExtensions.UpsertAsync Couchbase.KeyValue.CouchbaseCollection.UpsertAsync Couchbase.KeyValue.ICouchbaseCollection.UpsertAsync Couchbase.KeyValue.CollectionExtensions.MutateInAsync Couchbase.KeyValue.CouchbaseCollection.MutateInAsync Couchbase.KeyValue.ICouchbaseCollection.MutateInAsync Couchbase.KeyValue.BinaryCollectionExtensions.IncrementAsync Couchbase.KeyValue.CouchbaseCollection.IncrementAsync Couchbase.KeyValue.IBinaryCollection.IncrementAsync Couchbase.KeyValue.BinaryCollectionExtensions.DecrementAsync Couchbase.KeyValue.CouchbaseCollection.DecrementAsync Couchbase.KeyValue.IBinaryCollection.DecrementAsync Couchbase.KeyValue.CollectionExtensions.TouchAsync Couchbase.KeyValue.CouchbaseCollection.TouchAsync Couchbase.KeyValue.ICouchbaseCollection.TouchAsync |
Select | 2.x |
Couchbase.CouchbaseBucket.Get Couchbase.MemcachedBucket.Get Couchbase.Core.IBucket.Get Couchbase.Cluster.QueryAsync Couchbase.CouchbaseBucket.QueryAsync Couchbase.MemcachedBucket.QueryAsync Couchbase.Core.IBucket.QueryAsync Couchbase.Core.ICluster.QueryAsync Couchbase.N1QL.IQueryClient.QueryAsync Couchbase.N1QL.QueryClient.QueryAsync Couchbase.Search.ISearchClient.QueryAsync Couchbase.Search.SearchClient.QueryAsync Couchbase.Cluster.Query Couchbase.CouchbaseBucket.Query Couchbase.MemcachedBucket.Query Couchbase.Core.IBucket.Query Couchbase.Core.ICluster.Query Couchbase.N1QL.IQueryClient.Query Couchbase.N1QL.QueryClient.Query Couchbase.Search.ISearchClient.Query Couchbase.Search.SearchClient.Query Couchbase.CouchbaseBucket.GetAndTouch Couchbase.MemcachedBucket.GetAndTouch Couchbase.Core.IBucket.GetAndTouch Couchbase.CouchbaseBucket.GetAndLock Couchbase.MemcachedBucket.GetAndLock Couchbase.Core.IBucket.GetAndLock Couchbase.CouchbaseBucket.GetWithLock Couchbase.MemcachedBucket.GetWithLock Couchbase.Core.IBucket.GetWithLock Couchbase.CouchbaseBucket.GetFromReplica Couchbase.MemcachedBucket.GetFromReplica Couchbase.Core.IBucket.GetFromReplica Couchbase.CouchbaseBucket.GetDocument Couchbase.MemcachedBucket.GetDocument Couchbase.Core.IBucket.GetDocument Couchbase.CouchbaseBucket.GetAndTouchDocument Couchbase.MemcachedBucket.GetAndTouchDocument Couchbase.Core.IBucket.GetAndTouchDocument Couchbase.CouchbaseBucket.GetDocumentFromReplica Couchbase.MemcachedBucket.GetDocumentFromReplica Couchbase.Core.IBucket.GetDocumentFromReplica Couchbase.CouchbaseBucket.LookupIn Couchbase.MemcachedBucket.LookupIn Couchbase.Core.IBucket.LookupIn Couchbase.CouchbaseBucket.GetAsync Couchbase.MemcachedBucket.GetAsync Couchbase.Core.IBucket.GetAsync Couchbase.CouchbaseBucket.GetAndLockAsync Couchbase.MemcachedBucket.GetAndLockAsync Couchbase.Core.IBucket.GetAndLockAsync Couchbase.CouchbaseBucket.GetAndTouchAsync Couchbase.MemcachedBucket.GetAndTouchAsync Couchbase.Core.IBucket.GetAndTouchAsync Couchbase.CouchbaseBucket.GetWithLockAsync Couchbase.MemcachedBucket.GetWithLockAsync Couchbase.Core.IBucket.GetWithLockAsync Couchbase.CouchbaseBucket.GetFromReplicaAsync Couchbase.MemcachedBucket.GetFromReplicaAsync Couchbase.Core.IBucket.GetFromReplicaAsync Couchbase.CouchbaseBucket.GetDocumentAsync Couchbase.MemcachedBucket.GetDocumentAsync Couchbase.Core.IBucket.GetDocumentAsync Couchbase.CouchbaseBucket.GetAndTouchDocumentAsync Couchbase.MemcachedBucket.GetAndTouchDocumentAsync Couchbase.Core.IBucket.GetAndTouchDocumentAsync Couchbase.CouchbaseBucket.GetDocumentFromReplicaAsync Couchbase.MemcachedBucket.GetDocumentFromReplicaAsync Couchbase.Core.IBucket.GetDocumentFromReplicaAsync |
Select | 3.x |
Couchbase.KeyValue.CollectionExtensions.GetAsync Couchbase.KeyValue.CouchbaseCollection.GetAsync Couchbase.KeyValue.ICouchbaseCollection.GetAsync Couchbase.Cluster.QueryAsync Couchbase.ICluster.QueryAsync Couchbase.KeyValue.CollectionExtensions.LookupInAsync Couchbase.KeyValue.CouchbaseCollection.LookupInAsync Couchbase.KeyValue.ICouchbaseCollection.LookupInAsync, Couchbase.KeyValue.CollectionExtensions.GetAndTouchAsync Couchbase.KeyValue.CouchbaseCollection.GetAndTouchAsync Couchbase.KeyValue.ICouchbaseCollection.GetAndTouchAsync Couchbase.KeyValue.CollectionExtensions.GetAndLockAsync Couchbase.KeyValue.CouchbaseCollection.GetAndLockAsync Couchbase.KeyValue.ICouchbaseCollection.GetAndLockAsync |
Delete | 2.x | Couchbase.CouchbaseBucket.Remove Couchbase.MemcachedBucket.Remove Couchbase.Core.IBucket.Remove Couchbase.CouchbaseBucket.RemoveAsync Couchbase.MemcachedBucket.RemoveAsync Couchbase.Core.IBucket.RemoveAsync |
Delete | 3.x | Couchbase.KeyValue.CollectionExtensions.RemoveAsync Couchbase.KeyValue.CouchbaseCollection.RemoveAsync Couchbase.KeyValue.ICouchbaseCollection.RemoveAsync |
What results can you expect?
Objects
Icon | Description |
---|---|
DotNet Couchbase Cluster | |
DotNet Couchbase Bucket | |
DotNet Couchbase Collection | |
DotNet Unknown Cluster | |
|
DotNet Unknown Couchbase Bucket |
DotNet Unknown Couchbase Collection |
Links
Links are created for transaction and function point needs:
Link type | Source and destination of link | Methods supported |
---|---|---|
belongsTo | From DotNet Couchbase Bucket object to DotNet Couchbase Cluster object |
- |
useLink | Between the caller .NET Class / Method objects and DotNet Couchbase Buckets/Collections objects | OpenBucket OpenBucketAsync GetBucket GetBucketAsync CreateBucket CreateBucketAsync CollectionAsync Collection DefaultCollection DefaultCollectionAsync |
useInsertLink | Between the caller .NET Class / Method objects and DotNet Couchbase Buckets/Collections objects | Insert InsertAsync |
useDeleteLink | Between the caller .NET Class / Method objects and DotNet Couchbase Buckets/Collections objects | Remove RemoveAsync |
useSelectLink |
Between the caller .NET Class / Method objects and DotNet Couchbase Buckets/Collections objects | Get GetAndTouch GetAndLock GetWithLock GetFromReplica GetDocument GetAndTouchDocument GetDocumentFromReplica LookupIn GetAsync LookupInAsync GetAndLockAsync GetAndTouchAsync GetWithLockAsync GetFromReplicaAsync GetDocumentAsync GetAndTouchDocumentAsync GetDocumentFromReplicaAsync |
useUpdateLink | Between the caller .NET Class / Method objects and DotNet Couchbase Buckets/Collections objects | Replace Upsert Append Prepend Increment Decrement MutateIn MutateInAsync ReplaceAsync UpsertAsync AppendAsync PrependAsync IncrementAsync DecrementAsync TouchAsync |
What results can you expect?
Some example scenarios are shown below:
Cluster Creation and Bucket Opening (2.x)
class Program
{
private static Cluster cluster_1 = new Cluster();
private const string bucket_name = "GeoBucket";
private static IBucket geobucket;
static void Main(string[] args)
{
AuthenticateCluster();
CreateBucket();
CouchbaseOpenBucket();
}
private static void AuthenticateCluster()
{
Console.WriteLine("Cluster Created - Localhost");
var authenticator = new PasswordAuthenticator("Administrator", "123456");
cluster_1.Authenticate(authenticator);
}
private static void CreateBucket()
{
var cm = cluster_1.CreateManager();
cm.CreateBucket(bucket_name);
}
private static void CouchbaseOpenBucket()
{
geobucket = cluster_1.OpenBucket(bucket_name);
return;
}
}
Using ClusterHelper for cluster and bucket (2.x)
private static void TestClusterHelper4()
{
var config = new ClientConfiguration {
Servers = new List<Uri>{
new Uri("http://192.168.56.101:8091"),
new Uri("http://192.168.56.102:8091")
} };
ClusterHelper.Initialize(config);
var chbucket = ClusterHelper.GetBucket("defaultWayt");
}
Insert Operation (2.x)
private static void InsertDocumentInBucket()
{
geobucket.Insert(SetKarDoc());
geobucket.Insert(SetGoaDoc());
geobucket.Insert(SetBengaluruDoc());
geobucket.Insert(SetChandigarhDoc());
}
Update Operation (2.x)
UpsertDocumentInBucket
private static void UpsertDocumentInBucket()
{
geobucket.Upsert(MysuruDoc());
}
Upsert
Increment
Decrement
Append and Prepend
Select Operation (2.x)
private static void GetDocumentsFromBucket()
{
var result = geobucket.GetDocument<dynamic>("Goa").Content;
}
Delete Operation (2.x)
private static void DeleteDocumentInBucket()
{
geobucket.Remove(MysuruDoc());
}
Cluster, Bucket and Collection Creation (3.x)
class Program
{
private const string users_collection = "collection6";
public async Task<Employees> GetTheDoc(Employees value)
{
var cluster4 = await Cluster.ConnectAsync("couchbase://localhost", "adm", "jim753");
var bucket = await cluster4.BucketAsync("NewBucket");
// get a user-defined collection reference
var scope = await bucket.ScopeAsync("tenant_agent_00");
var collection = await scope.CollectionAsync(users_collection);
var collection_in_default_scope = await bucket.CollectionAsync("bookings");
}
}
Insert Operation (3.x)
InsertDocumentInBucket
//create
public async Task<Employees> PostEmployee(ICluster cluster3, Employees value)
{
var bucket = await cluster3.BucketAsync(samplebucket);
var collection = bucket.DefaultCollection();
// You can access multiple buckets using the same Cluster object.
var anotherBucket = await cluster3.BucketAsync("AnotherBucket");
// You can access collections other than the default
var customerC = anotherBucket.Scope("customer-c");
var trains = customerC.Collection("trains");
int idvalue = value.id;
var collectiondataa= await trains.InsertAsync( idvalue.ToString(),value );
if (collectiondataa == null)
{
logger.LogError("Error in creating");
}
return null;
}
Update Operation (3.x)
//update
public async Task<Employees> OnlyUpdateEmployee(ICluster cluster_new_2, Employees value)
{
var bucket = await cluster_new_2.BucketAsync("SmallBucket");
var collection = bucket.DefaultCollection();
// You can access multiple buckets using the same Cluster object.
var anotherBucket = await cluster_new_2.BucketAsync("ShiningBucket");
// You can access collections other than the default
var customerD = anotherBucket.Scope("customer-D");
var bikes = customerD.Collection("bikes");
int idvalue = value.id;
var collectiondataa= await bikes.ReplaceAsync( idvalue.ToString(),value );
if (collectiondataa == null)
{
logger.LogError("Error in creating");
}
return null;
}
Select Operation (3.x)
GetDocumentFromBucket
//get
public async Task<Employees> GetTheDoc(ICluster cluster4, Employees value)
{
var bucket = await cluster4.BucketAsync(newbucket);
// get a user-defined collection reference
var scope = await bucket.ScopeAsync("tenant_agent_00");
var collection = await scope.CollectionAsync(users_collection);
var collection_in_default_scope = await bucket.CollectionAsync("bookings");
// Get Document
var getResult = await collection.GetAsync("my-document-key");
}
Delete Operation (3.x)
public async Task<Employees> DeleteEmployeeById(ICluster cluster1, int id)
{
try
{
var bucket = await cluster1.BucketAsync("EmployeesBucket");
// You can access collections other than the default
var customer10 = bucket.Scope("customer-10");
var bluecolour = customer10.Collection("bluecolour");
int idvalue = value.id;
var collectiondataa = await bluecolour.RemoveAsync( idvalue.ToString() );
if (collectiondataa == null)
{
logger.LogError("Error in creating");
}
return null;
}
catch (BucketNotFoundException)
{
logger.LogError("Bucket not found");
throw;
}
}
N1QL Query (2.x)
private static void QueryBucketUsingN1QL()
{
var create_index = "CREATE PRIMARY INDEX ON " + bucket_name;
geobucket.Query<dynamic>(create_index);
var queryResult = geobucket.Query<dynamic>("SELECT name, state FROM GeoBucket WHERE type = \'city\' and capital=\'Yes\'");
foreach (var row in queryResult.Rows)
Console.WriteLine(row);
}
N1QL Query (3.x)
public async Task<List<Employees>> GetEmployees(ICluster cluster_query)
{
try
{
var queryResult = await cluster_query.QueryAsync<Employees>("SELECT username,name,email,age,location,srccs,phoneNumber,salary,skill,managerName,address,id FROM Employees ", new Couchbase.Query.QueryOptions());
var queryResult2 = await cluster_query.QueryAsync<Employees>("UPDATE cars SET door = red, window = transparent, WHERE door = blue; ", new Couchbase.Query.QueryOptions());
List<Employees> empList = new List<Employees>();
await foreach (var row in queryResult)
{
empList.Add(row);
}
return empList;
}
catch (IndexFailureException)
{
logger.LogError("Bucket not found");
throw;
}
}
Sub-Document Operations
The following methods sub-document operations are supported:
- LookupIn
- MutateIn
- ArrayInsert
- ArrayAppend
- ArrayPrepend
- ArrayAddUnique
- Remove
- Replace
- Insert
- Upsert
LookupIn
public static void LookupInMethod2( string id)
{ var builder = geobucket.LookupIn<dynamic>(id).
Get("type").
Get("country").
Exists("notfound");
}
MutateIn
public static void SubDocMisc(string id, string path, string replace_path, object value)
{
geobucket.MutateIn<dynamic>(id).
Remove(path).
Replace(replace_path, value).
Execute();
}
Asynchronous API
- OpenBucketAsync
- GetBucketAsync
- CreateBucketAsync
- CollectionAsync
- DefaultCollectionAsync
- InsertAsync
- ReplaceAsync
- UpsertAsync
- AppendAsync
- PrependAsync
- IncrementAsync
- DecrementAsync
- QueryAsync
- GetAsync
- GetAndLockAsync
- GetAndTouchAsync
- GetWithLockAsync
- GetFromReplicaAsync
- GetDocumentAsync
- GetAndTouchDocumentAsync
- GetDocumentFromReplicaAsync
- TouchAsync
- LookupInAsync
- MutateInAsync
- QueryAsync
Reading App.config
Increment Operation 2.x
static void Increment(IBucket bucket1, string key)
{
var result = bucket1.Increment(key);
if (result.Success)
{
Console.WriteLine(result.Value);
}
}
app.config
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
</startup>
<configSections>
<sectionGroup name="couchbaseClients">
<section name="couchbase" type="Couchbase.Configuration.Client.Providers.CouchbaseClientSection, Couchbase.NetClient" />
</sectionGroup>
</configSections>
<couchbaseClients>
<couchbase username="Administrator" password="123456">
<servers>
<add uri="http://192.168.56.101:8091"></add>
</servers>
<buckets>
<add name="mybucket"></add>
<add name="mybucket2"></add>
</buckets>
</couchbase>
</couchbaseClients>
</configuration>
Known Limitations
- If bucket/collection names are not resolved, the links are created between methods and unknown bucket/collection objects