-
Notifications
You must be signed in to change notification settings - Fork 32
Expand file tree
/
Copy pathCloud.cs
More file actions
63 lines (54 loc) · 2.4 KB
/
Copy pathCloud.cs
File metadata and controls
63 lines (54 loc) · 2.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
using System;
using System.Threading.Tasks;
using Couchbase;
using Couchbase.Query;
using Couchbase.Management.Query;
// using Microsoft.Extensions.DependencyInjection;
// using Microsoft.Extensions.Logging;
// using Serilog;
// using Serilog.Extensions.Logging;
namespace net3
{
class Program
{
static async Task Main(string[] args)
{
// Update this to your cluster
var endpoint = "cb.13d1a4bc-31a8-49c6-9ade-74073df0799f.dp.cloud.couchbase.com";
var bucketName = "couchbasecloudbucket";
var username = "user";
var password = "password";
// User Input ends here.
// IServiceCollection serviceCollection = new ServiceCollection();
// serviceCollection.AddLogging(builder => builder.AddFilter(level => level >= LogLevel.Trace));
// var loggerFactory = serviceCollection.BuildServiceProvider().GetService<ILoggerFactory>();
// loggerFactory.AddFile("Logs/myapp-{Date}.txt", LogLevel.Debug);
// Initialize the Connection
var opts = new ClusterOptions().WithCredentials(username, password);
// opts = opts.WithLogging(loggerFactory);
opts.IgnoreRemoteCertificateNameMismatch = true;
var cluster = await Cluster.ConnectAsync("couchbases://"+endpoint, opts);
var bucket = await cluster.BucketAsync(bucketName);
var collection = bucket.DefaultCollection();
// Store a Document
var upsertResult = await collection.UpsertAsync("king_arthur", new {
Name = "Arthur",
Email = "kingarthur@couchbase.com",
Interests = new[] { "Holy Grail", "African Swallows" }
});
// Load the Document and print it
var getResult = await collection.GetAsync("king_arthur");
Console.WriteLine(getResult.ContentAs<dynamic>());
// Perform a N1QL Query
var queryResult = await cluster.QueryAsync<dynamic>(
String.Format("SELECT name FROM `{0}` WHERE $1 IN interests", bucketName),
new QueryOptions().Parameter("African Swallows")
);
// Print each found Row
await foreach (var row in queryResult)
{
Console.WriteLine(row);
}
}
}
}