using System; using System.Collections.Generic; using System.Collections.Specialized; using System.Configuration; using System.Linq; using System.Text; using System.Threading.Tasks; using Couchbase.Configuration.Client; using Couchbase.Core; using Couchbase.IO; namespace Couchbase.Examples.SubDocumentAPI { class Program { static void Main(string[] args) { ClusterHelper.Initialize(new ClientConfiguration { Servers = new List { new Uri(ConfigurationManager.AppSettings["couchbaseUri"]) } }); var bucket = ClusterHelper.GetBucket("default"); const string id = "puppy"; var dog = new { Type = "dog", Breed = "Pitbull/Chihuahua", Name = "Puppy", Toys = new List {"squeaker", "ball", "shoe"}, Owner = new { Type = "servant", Name = "Don Knotts", Age = 63 }, Attributes = new Dictionary { {"Fleas", true}, {"Color", "white"}, {"EyeColor", "brown"}, {"Age", 5}, {"Dirty", true }, {"Sex", "female" } }, Counts = new List { 1} }; Reset(bucket, id, dog); LookupInChaining(bucket, id); ClusterHelper.Close(); Console.Read(); } static void Reset(IBucket bucket, string id, dynamic doc) { var result = bucket.Upsert(new Document { Id = id, Content = doc }); Console.WriteLine("Updated {0} - {1}", id, result.Status); } public static void LookupInChaining(IBucket bucket, string id) { var builder = bucket.LookupIn(id). Get("type"). Get("name"). Get("owner"). Exists("notfound"); var fragment = builder.Execute(); if (fragment.OpStatus("type") == ResponseStatus.Success) { string format = "Path='{0}' Value='{1}'"; Console.WriteLine(format, "type", fragment.Content("type")); } GetDisplay(fragment, "type"); GetDisplay(fragment, "name"); GetDisplay(fragment, "owner"); } static void GetDisplay(IDocumentFragment fragment, string path) { string format = "Path='{0}' Value='{1}'"; Console.WriteLine(format, path, fragment.Content(path)); } } }