DBIndex class

Configuration class for MongoDB database indexes.

This class encapsulates all the configuration options needed to create a MongoDB index. It provides a convenient way to define index properties that will be used when creating indexes on collection fields.

MongoDB indexes improve query performance and can enforce constraints like uniqueness. This class supports all major index options including:

  • Single field and compound indexes
  • Unique constraints
  • Sparse indexes (ignore null values)
  • Partial indexes with filter expressions
  • Background index creation
  • Custom collation for text sorting

Example:

var emailIndex = DBIndex(
  key: 'email',
  unique: true,
  sparse: true,
);

var compoundIndex = DBIndex(
  keys: {'category': 1, 'createdAt': -1},
  name: 'category_date_idx',
);

Constructors

DBIndex.new({String? key, Map<String, dynamic>? keys, bool? unique, bool? sparse, bool? background, bool? dropDups, Map<String, dynamic>? partialFilterExpression, String? name, bool? modernReply, Map? collation})
Creates a new database index configuration.

Properties

background bool?
Whether to build the index in the background.
getter/setter pair
collation Map?
Collation specification for the index.
getter/setter pair
dropDups bool?
Whether to drop duplicate documents during index creation.
getter/setter pair
hashCode int
The hash code for this object.
no setterinherited
key String?
Single field name to index (alternative to keys).
getter/setter pair
keys Map<String, dynamic>?
Map defining compound index fields and their sort order.
getter/setter pair
modernReply bool?
Whether to use modern reply format for index creation.
getter/setter pair
name String?
Custom name for the index.
getter/setter pair
partialFilterExpression Map<String, dynamic>?
Filter expression for partial indexes.
getter/setter pair
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
sparse bool?
Whether to create a sparse index.
getter/setter pair
unique bool?
Whether the index should enforce uniqueness constraint.
getter/setter pair

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited

Operators

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