Create a Database
In this lesson you’ll be introduced to Couchbase Lite, our embedded NoSQL database. You’ll learn how to create a new embedded database and optionally use databases pre-packaged in your application.
Getting Started
Download the Visual Studio project.
Create a new database
The entrypoint in the Couchbase Lite SDK is the Manager class. There is no limit to how many databases can be created or opened on the device. You can think of a database as a namespace for documents and several databases can be used in the same app (one database per user of the app is a common pattern). The code below creates an empty database.
// This code can be found in CoreApp.cs
// in the OpenDatabase(string, string, string) method
var encryptionKey = default(SymmetricKey);
if(key != null) {
encryptionKey = new SymmetricKey(key);
}
var options = new DatabaseOptions {
Create = true,
EncryptionKey = encryptionKey
};
Database = AppWideManager.OpenDatabase(dbName, options);
if(newKey != null) {
Database.ChangeEncryptionKey(new SymmetricKey(newKey));
}
Here you’re using the openDatabaseNamed method where the database is the user currently logged in and options.create is set to true.
| You can ignore the encryption flag. Database encryption will be covered in the Adding Security lesson. |