Repository navigation
Views
A [ManagedView] declares a read-only view and the pipeline it runs
over another collection or view. up creates and updates it like a
collection definition.
[ManagedView("active_customers", on: "customers")]
public sealed class ActiveCustomers : IViewDefinition<Customer>
{
public void Define(ViewBuilder<Customer> view) =>
view.Pipeline(p => p
.Match(c => c.Active)
.Project(c => new { c.Email, c.Tier }))
.Collation(new Collation("en", strength: CollationStrength.Secondary));
}-
[ManagedView(name, on:)]names the view and the collection or view it reads from. -
IViewDefinition<TDocument>describes it on aViewBuilder. Implementing it more than once is a build error (MM0010). -
Pipelinetakes the driver's pipeline builder, aPipelineDefinition, a JSON array string or a list ofBsonDocumentstages. -
Collationis optional.
A view can't write, so a $out or
$merge stage makes the definition invalid.
The check follows the places MongoDB runs a nested pipeline (each facet of a $facet, and the pipeline of a
$lookup or $unionWith), so one buried in a sub-pipeline is still rejected. A field or literal that merely happens
to be named $out or $merge (for example under $literal) is data, not a stage, and is left alone.
| On the server | up |
|---|---|
| Missing |
create with viewOn, pipeline and collation. |
| A different pipeline or source |
collMod, in place. |
| A different collation | Drops the view and creates it again (a view's collation can't change). |
| A collection with the same name | Blocked, exit code 4. |
Views are applied after every collection, and a view on another view after the one it reads from. Views that read from
each other in a cycle are a build error (MM0011).
With collections.prune: drop, undeclared views are dropped. Anything a declared or kept
view depends on is never pruned.
Kevsoft.MigrateMongo ·
NuGet ·
Releases ·
Issues ·
Found a mistake? These pages live in
wiki/ on main; pull requests welcome.
Get started
Migrations
- Writing Migrations
- Transactions
- Recording Results
- Dependency Injection
- Custom Templates
- Adopting an Existing Database
Collections
- Managing Collections
- Indexes
- Search Indexes
- Collection Options
- Validators
- Views
- Undeclared Collections
Deploying
Connecting
Reference
Concepts