parent property

DocumentReference<T>? get parent

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<T>? get parent {
  if (!_queryOptions.parentPath.isDocument) return null;

  return DocumentReference<T>._(
    firestore: firestore,
    path: _queryOptions.parentPath as _QualifiedResourcePath,
    converter: _queryOptions.converter,
  );
}