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

Fetching collections with + characters in their path #51

Open
a-shine opened this issue Aug 28, 2024 · 3 comments
Open

Fetching collections with + characters in their path #51

a-shine opened this issue Aug 28, 2024 · 3 comments
Assignees
Labels
bug Something isn't working

Comments

@a-shine
Copy link

a-shine commented Aug 28, 2024

Describe the bug
When attempting to fetch documents from a collection using the firestore.collection("/collection+a/lF1kvtRAYMqmdInT7iJK/subcollection").get() the snapshot always returns snapshot.docs.length as 0 if the provided path contains a + character.

To Reproduce
Created 2 identical collection hierarchies:

  • /collection+a/lF1kvtRAYMqmdInT7iJK/subcollection
  • /collectiona/lF1kvtRAYMqmdInT7iJK/subcollection

Both contain a single document (again with the same id sTPO9C0HbZJUlKcm1QwR for control)

QuerySnapshot snapshot = await firestore
        .collection("/collectiona/lF1kvtRAYMqmdInT7iJK/subcollection")
        .get();
print('Number of documents: ${snapshot.docs.length}'); // returns 1


QuerySnapshot snapshot = await firestore
        .collection("/collection+a/lF1kvtRAYMqmdInT7iJK/subcollection")
        .get();
print('Number of documents: ${snapshot.docs.length}'); // returns 0

Expected behavior
I would expect the + character to have no impact on returning a collection as it is a valid character for a collection path.

@a-shine a-shine added the bug Something isn't working label Aug 28, 2024
@HeySreelal
Copy link
Contributor

HeySreelal commented Sep 20, 2024

I spent some time on this today and want to add a little more debugging information on this for anyone referring this.

When + character is present in the path, especially when used with sub collections it is treated a s space character ( ), ie., /collection+a/abc/subcol is treated as /collection a/abc/subcol. Which pretty much seems like a encoding issue.

Which in turn means:

  1. This works fine as intended, outputs Number of documents: 1 (or the number of documents correctly)
  final snapshot = await db.collection("collection+a").get();
  print('Number of documents: ${snapshot.docs.length}');
  1. Setting up a collection & document like "collection a/abc/subcol/xyz" and running:
  final snapshot = await db.collection("collection+a/abc/subcol").get();
  print('Number of documents: ${snapshot.docs.length}');

Interestingly outputs, Number of documents: 1

@rrousselGit, just CC-ing you, I'll try to dig in further, if you have any leads on this please let me know, thanks :)

@Ehesp
Copy link
Member

Ehesp commented Sep 21, 2024

Might be worth looking at the node sdk here and validating if it's encoding the path value sent with requests.

@HeySreelal
Copy link
Contributor

Hi @Ehesp, I tried looking into both libraries and inspected the requests.

On NodeJS SDK the request looks something like this:

{
  parent: 'projects/project_id/databases/(default)/documents/collection+a/abc',
  structuredQuery: {
    from: [ { 'collectionId': 'subcol' } ]
  }
}

While on this library, we call the parent: projects/project_id/databases/(default)/documents/collection+a/abc with body:

{
  "structuredQuery": {
    "from": [{ "collectionId": "subcol" }]
  }
}

Which pretty much looks same. Apart from that, there's two specific headers NodeJS library add, google-cloud-resource-prefix and x-goog-request-params, that we don't. Anyway, that also doesn't seems be causing the issue.

May be I'm missing something?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants