parent property

A reference to the containing Document if this is a subcollection, else null.

final collectionRef = firestore.collection('col/doc/subcollection');
final documentRef = collectionRef.parent;
print('Parent name: ${documentRef.path}');

Implementation

DocumentReference<DocumentData>? get parent {
  if (!_queryOptions.parentPath.isDocument) return null;

  return DocumentReference<DocumentData>._(
    firestore: firestore,
    path: _queryOptions.parentPath,
    converter: _jsonConverter,
  );
}