Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Querying subcollection of subcollection seems to inject random doc number on its path #307

Open
brunodmn opened this issue Jun 22, 2022 · 1 comment

Comments

@brunodmn
Copy link

I have a structure similar to this:

@Collection('baby_foo')
 class BabyFoo {
 id: string;
name:string;
}

@Collection('daddy_foo')
 class DaddyFoo {
 id: string;
name:string;
@SubCollection(BabyFoo, 'babby_foo')
babby_foo: ISubCollection<BabyFoo>;
}

@Collection('grandpa_foo')
 class GrandpaFoo {
 id: string;
name:string;
@SubCollection(DaddyFoo, 'daddy_foo')
daddy_foo: ISubCollection<DaddyFoo>;
}

The grandpa_foo collection has many docs.
Each grandpa_foo collection has has only one daddy_foo doc with id "0"
Each daddy_foo collection has many baby_foo docs (array)

I am trying to make them a big nested family querying all over

const repo = fireorm.getRepository(GrandpaFoo);
const grandpa = await repo.findOne()
const daddy = await grandpa.daddy_foo.findById("0")
const babies = await daddy.babby_food.find()
console.log("family babies: ", babies.length);

The odd thing is...some queries will work, for these, daddy will log path (under baby_foo BaseFirestoreRepository):
console.log('daddy',daddy); output:

...
faturas: BaseFirestoreRepository {
  ...
  path: 'grandpa_foo/cOv1qwRJZZXxrfgTp4EOtGZ55PD1/daddy_foo/0/babby_foo',
  ...
}
...

Another queries will not work, for these, daddy will log path (under baby_foo BaseFirestoreRepository):
console.log('daddy',daddy); output:

...
faturas: BaseFirestoreRepository {
  ...
  path: 'grandpa_foo/cOv1qwRJZZXxrfgTp4EOtGZ55PD1/daddy_foo/1/babby_foo',
  ...
}
...

Noticed the 1 instead of 0 referencing a non existent document? Its random.

I tried const daddy = await grandpa.daddy_foo.findOne() instead of const daddy = await grandpa.daddy_foo.findById("0") with same results.

Querying with firestore would look like bellow, and work as expected:

const babies = await this.firestore.collection('grandpa_foo').doc(cOv1qwRJZZXxrfgTp4EOtGZ55PD1).collection('daddy_foo').doc('0').collection('baby_foo').get()
console.log("family babies: ", babies.docs.length)

I hope you understands the explanation...A I doing something wrong or its just some strange bug?

Thanks!

@wovalle
Copy link
Owner

wovalle commented Jun 23, 2022

Hi @brunodmn, looking at the issue I don't think such random value should be possible. SubCollection paths are assembled from the ids returned by a query.

In your second example, daddy's id should always be 0 since you're only fetching the document with the id 0 in const daddy = await grandpa.daddy_foo.findById("0")

To be able to properly debug this issue you need to provide a small project reproducing the bug since we cannot se the big picture with small files

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants