Home > Enterprise >  Cannot check for "Long Named" Document existence in Firebase?
Cannot check for "Long Named" Document existence in Firebase?

Time:04-27

I've been working with Flutter and Firebase lately, I'm facing a confusing problem today and would like some help.

I have a Collection in Firebase Cloud Firestore that contains Documents which their names are quite long. The photo below shows them:

enter image description here

I wrote a function in Dart to check the existence of a specific document, it's also pretty simple:

    Future<String> checkForExistance(String mnemonic) async {
    final String seedHex = bip39.mnemonicToSeedHex(mnemonic);
    final snapShot = await FirebaseFirestore.instance
        .collection('wallets')
        .doc(seedHex)
        .get();

    if (!snapShot.exists) {
      if (kDebugMode) {
        print('SnapShot not exist');
      }
      return 'NO_IDEA';
    } else {
      if (kDebugMode) {
        print('Snapshot Exist');
      }
      return seedHex;
    }
  }

The return result is always 'SnapShot not exist'.

The return is always 'SnapShot not exist' even though I've made sure I'm checking for the existence of exactly what I need.

Even when I hard coded the name of one of those documents, the result is 'SnapShot not exist' (this is what confuses me).

Future<String> checkForExistance(String mnemonic) async {
    final String seedHex = bip39.mnemonicToSeedHex(mnemonic);
    final snapShot = await FirebaseFirestore.instance
        .collection('wallets')
        .doc(**'hard coded'**)
        .get();

    if (!snapShot.exists) {
      if (kDebugMode) {
        print('SnapShot not exist');
      }
      return 'NO_IDEA';
    } else {
      if (kDebugMode) {
        print('Snapshot Exist');
      }
      return seedHex;
    }
  }

So I tried creating a document with a shorter name (the 's' at the end of the image) and hard coded it, the results returned as expected which is 'Snapshot Exist'.

Is it because my documents name is too long that Firebase search is not working as expected?

Thanks for everyone's help.

CodePudding user response:

From what I can see in the screenshot the document names are shown in italic, which means that there is no document with that name and the console merely shows it because there are subcollections under that path.

That also explains why you can't load those documents through the API, there are no documents to load.

You will either already have to know of the existence of these paths, or you can load the documents from the subcollections with a collection group query and then determine the parent path(s) from that.

  • Related