diff --git a/packages/firestore/lib/modular/index.js b/packages/firestore/lib/modular/index.js index 46eb2d8c4c..18c9dccb1c 100644 --- a/packages/firestore/lib/modular/index.js +++ b/packages/firestore/lib/modular/index.js @@ -44,6 +44,11 @@ export function doc(parent, path, ...pathSegments) { if (pathSegments && pathSegments.length) { path = path + '/' + pathSegments.map(e => e.replace(/^\/|\/$/g, '')).join('/'); } + + if ('collection' in parent) { + const [firstSegment, ...restSegments] = path.split('/'); + return parent.collection(firstSegment).doc(restSegments.join('/')); + } return parent.doc(path); } @@ -59,6 +64,11 @@ export function collection(parent, path, ...pathSegments) { path = path + '/' + pathSegments.map(e => e.replace(/^\/|\/$/g, '')).join('/'); } + if ('doc' in parent) { + const [firstSegment, ...restSegments] = path.split('/'); + return parent.doc(firstSegment).collection(restSegments.join('/')); + } + return parent.collection(path); }