couchbase C# SDK Insert Document Sync


Example

There are two basic ways in which you can Insert a document

  1. Create a document, Then insert it
var bucket = cluster.OpenBucket("default");

var document = new Document<dynamic>
    {
        Id = "doc_net",
        Content = new
        {
            name = "Roi",
            lastName = "Katz",
            someRandomField="Very important data!"
        },
        Expiry = 0, // TTL in ms
    };

    bucket.Insert(document);
  1. Use a Serialized object and Newtonsoft JSON.net
  public class MyDataObject
    {
        public string Name { get; set; }
        public int LastName { get; set; }
        public string SomeRandomField { get; set; }
    }

And Use it to insert your data

var dataObject = new MyDataObject();
//...Fill up the object
bucket.Insert("MyUniqueDocumentKey", dataObject, 10); // Insert a document with 10 seconds TTL - or you can use a TimeSpan

You can also sent persistence of replication factor while you insert the document. Replication and persistence settings of the document