Document<T> class

A document in a Collection.

In relational databases, "document" means a row.

An example:

Future<void> main() async {
  // Use an in-memory database
  final database = MemoryDatabaseAdapter().database();

  // Our collection
  final collection = database.collection('pizzas');

  // Our document
  final document = collection.newDocument();

  await document.insert({
    'name': 'Pizza Margherita',
    'rating': 3.5,
    'ingredients': ['dough', 'tomatoes'],
    'similar': [
      database.collection('recipes').document('pizza_funghi'),
    ],
  });
  print('Successfully inserted pizza.');

  await document.patch({
    'rating': 4.5,
  });
  print('Successfully patched pizza.');

  await document.delete();
  print('Successfully deleted pizza.');
}

Constructors

Document(Collection parent, String documentId)
Constructs a document. Usually you should call the method collection.document("id") instead of this constructor.

Properties

database Database
Returns database where the document is.
read-only
documentId String
A non-blank document identifier. [...]
final
hashCode int
The hash code for this object. [...]
read-only, override
parent Collection
Collection where the document is.
final
parentDatabase Database
read-only
runtimeType Type
A representation of the runtime type of the object.
read-only, inherited

Methods

delete({Reach reach, bool mustExist: false}) Future<void>
Deletes the document. [...]
exists({Reach reach: Reach.regional}) Future<bool>
Tells whether the document exists. [...]
get({Schema schema, Reach reach}) Future<Snapshot>
Returns the current snapshot. [...]
getIncrementally({Schema schema, Reach reach}) Stream<Snapshot>
Returns an incrementally improving stream snapshots until the best available snapshot has been received.
insert({Map<String, Object> data, Reach reach: Reach.regional}) Future<void>
Inserts the document. [...]
noSuchMethod(Invocation invocation) → dynamic
Invoked when a non-existent method or property is accessed. [...]
inherited
patch({Map<String, Object> data, Reach reach}) Future<void>
Patches the document. [...]
toString() String
Returns a string representation of this object.
override
update({Map<String, Object> data, Reach reach: Reach.regional}) Future<void>
Updates the document. [...]
upsert({Map<String, Object> data, Reach reach}) Future<void>
Upserts ("inserts or updates") the document. [...]
watch({Schema schema, Duration interval, Reach reach}) Stream<Snapshot>
Returns am infinite stream of snapshots. [...]

Operators

operator ==(dynamic other) bool
The equality operator. [...]
override