CreateViewCommand class

createView command.

Creates a view as the result of the applying the specified aggregation pipeline to the source collection or view. Views act as read-only collections, and are computed on demand during read operations. You must create views in the same database as the source collection. MongoDB executes read operations on views as part of the underlying aggregation pipeline.

The view definition pipeline cannot include the $out or the $merge stage. If the view definition includes nested pipeline (e.g. the view definition includes $lookup or $facet stage), this restriction applies to the nested pipelines as well.

The command accepts the following fields:

  • db Db The database on which create the collection

  • view String The view name to be created.

  • source String The name of the source collection or view from which to create the view. The name is not the full namespace of the collection or view; i.e. does not include the database name and implies the same database as the view to create. You must create views in the same database as the source collection.

  • pipeline List

    An array that consists of the aggregation pipeline stage(s). db.createView creates the view by applying the specified pipeline to the source collection or view.

    The view definition pipeline cannot include the $out or the $merge stage. If the view definition includes nested pipeline (e.g. the view definition includes $lookup or $facet stage), this restriction applies to the nested pipelines as well.

    The view definition is public; i.e. db.getCollectionInfos() and explain operations on the view will include the pipeline that defines the view. As such, avoid referring directly to sensitive fields and values in view definitions.

  • createViewOptions createViewOptions - Optional a set of optional values for the command

  • rawOption Map An alternative way to creteViewOptions to specify command options (must be manually set)

Constructors

CreateViewCommand(Db db, String view, String source, List pipeline, {CreateViewOptions? createViewOptions, Map<String, Object>? rawOptions})

Properties

canRetryRead bool
no setterinherited
collection DbCollection?
getter/setter pairinherited
command Map<String, Object>?
getter/setter pairinherited
connection Connection?
getter/setter pairinherited
db Db
getter/setter pairinherited
hashCode int
The hash code for this object.
no setterinherited
options Map<String, Object>
getter/setter pairinherited
readPreference ReadPreference?
getter/setter pairinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
session Object?
getter/setter pairinherited

Methods

$buildCommand() Map<String, Object>
inherited
clearSession() → void
inherited
execute({bool skipStateCheck = false}) Future<Map<String, dynamic>>
inherited
hasAspect(Aspect aspect) bool
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
processOptions(Map<String, dynamic> command) → void
inherited
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited