Here is a sample application for performing few CRUD operations.
Requirements: VS 2012
Steps:
Create a console Application and
1. GO to Tools > Library Package Manager > Package Console
2. Install-Package CouchbaseNetClient
Upsert - Insert new records or Update existing records
        
                  
      
Requirements: VS 2012
Steps:
Create a console Application and
1. GO to Tools > Library Package Manager > Package Console
2. Install-Package CouchbaseNetClient
Upsert - Insert new records or Update existing records
  private static void UpsertData()
        {
            using (var bucket = Cluster.OpenBucket())   // Opens "default" DB if DB name is not specified
            {
                var document = new Document<dynamic>
                {
                    Id = "Hello",
                    Content = new
                    {
                        name = "Couchbase"
                    }
                };                                                                  // Create Document/Row to be inserted
                var upsert = bucket.Upsert(document);
                if (upsert.Success)
                {
                    var get = bucket.GetDocument<dynamic>(document.Id);
                    document = get.Document;
                    var msg = string.Format("{0} {1}!", document.Id, document.Content.name);
                    Console.WriteLine(msg);
                }
            }
 private static void DeleteData()
        {
            using (var bucket = Cluster.OpenBucket())
            {
                var document = new Document<dynamic>
                {
                    Id = "Hello"
                };
                var get = bucket.GetDocument<dynamic>(document.Id);
                document = get.Document;
                var msg = string.Format("{0} {1}! Deleted", document.Id, document.Content.name);
                var remove = bucket.Remove(document); // Delete Document Using ID
                if (remove.Success)
                {
                    Console.WriteLine(msg);
                }
            }
        }
No comments:
Post a Comment