Browse the documentation

Basic CRUD

Insert, read, update and delete documents.

Insert

Add returns the new document's id. AddRange inserts many at once. An optional time-to-live removes a document automatically after it expires.

Guid id = orders.Add(new Order
{
    Reference = "SO-10042",
    CustomerName = "Contoso",
    Country = "BE",
    Total = 1299.50m
});

orders.AddRange(
[
    new Order { Reference = "SO-10043", CustomerName = "Fabrikam", Country = "NL", Total = 240m },
    new Order { Reference = "SO-10044", CustomerName = "Northwind", Country = "BE", Total = 88m }
]);

// A time-to-live removes the document automatically once it expires.
orders.Add(new Order { Reference = "QUOTE-7" }, ttl: TimeSpan.FromDays(30));

Read, update and delete

var id = orders.Add(new Order { Reference = "SO-10042", CustomerName = "Contoso", Country = "BE", Total = 1299.50m });

Order? order = orders.Find(id);

var openInBelgium = await orders.ListAsync(x => x.Country == "BE" && x.Status == "open");

orders.Update(id, order! with { Status = "shipped" });

orders.Delete(id);

Each operation has an asynchronous counterpart:

var id = await orders.AddAsync(order);
var loaded = await orders.FindAsync(id);
await orders.UpdateAsync(id, loaded! with { Status = "processing" });
await orders.DeleteAsync(id);

var everything = await orders.AllAsync();

Update and delete by predicate

int updated = await orders.UpdateWhereAsync(
    x => x.Status == "open" && x.Country == "BE",
    u => u.Set(x => x.Status, "processing"));

int removed = await orders.DeleteWhereAsync(x => x.Status == "cancelled");

When is a write durable?

By default a write returns only after it is committed to the write-ahead log, so a crash cannot lose an acknowledged write. If the commit does not complete in time, the write is reported as indeterminate rather than failed. Read Durability & recovery before adding retry logic.

An unhandled error has occurred. Reload X

Reconnecting

Restoring the connection to the server...

Still trying

Next attempt in seconds

Connection lost

We could not reach the server.