.NET

.NET

Edit on GitHub
Platform:

Add Couchbase Lite to your app

NuGet

  1. In Visual Studio, right-click on the desired project and select the menu to add a Nuget dependency.

  2. Search for 'Couchbase Lite' and select the latest version of the Couchbase.Lite package.

  3. Once Couchbase Lite is installed you can run the project with Couchbase Lite as a dependency.

Available packages

The following libraries are available.

Package Name Server
Couchbase.Lite.Storage.SystemSQLite To use SQLite as the storage type. This is the default.
Couchbase.Lite.Storage.SQLCipher To use SQLCipher as the storage type.
Couchbase.Lite.Storage.ForestDB To use ForestDB as the storage type.

Getting Started

Create a new Visual Studio or Xamarin Studio project and install Couchbase Lite by following the steps above.

Open the main file in your project and add the following.

// Create a manager
Manager manager = Manager.SharedInstance;
// Create or open the database named app
Database database = manager.GetDatabase("app");
// The properties that will be saved on the document
Dictionary<string, object> properties = new Dictionary<string, object>
{
    { "title", "Couchbase Mobile"},
    { "sdk", "C#" }
};
// Create a new document
Document document = database.CreateDocument();
// Save the document to the database
document.PutProperties(properties);
// Log the document ID (generated by the database)
// and properties
Console.WriteLine($"Document ID :: {document.Id}");
Console.WriteLine($"Learning {document.GetProperty("title")} with {document.GetProperty("sdk")}");

// Create replicators to push & pull changes to & from Sync Gateway.
Uri url = new Uri("http://localhost:4984/hello");
Replication push = database.CreatePushReplication(url);
Replication pull = database.CreatePullReplication(url);
push.Continuous = true;
pull.Continuous = true;

// Start replicators
push.Start();
pull.Start();

Build and run. Notice the document ID and property are printed to the console. The document was successfully persisted to the database.

Click the Start button. Notice the document ID and properties are logged to the Application Output.

Installing Sync Gateway ⟶