angularfire icon indicating copy to clipboard operation
angularfire copied to clipboard

How check if collection exist????

Open Skrigueztep opened this issue 3 years ago • 2 comments
trafficstars

Version info

Angular: 12.2.14

Firebase: 9.4.0

AngularFire: 7.2.1

Other (e.g. Ionic/Cordova, Node, browser, operating system):

Windows: 10 Node: 14.18.2 NPM: 6.14.15

How to reproduce these conditions

Failing test unit, Stackblitz demonstrating the problem

Steps to set up and reproduce

Sample data and security rules

Debug output

** Errors in the JavaScript console **

ERROR FirebaseError: Invalid document reference. Document references must have an even number of segments, but has 1.

** Output from firebase.database().enableLogging(true); **

Nothing

** Screenshots **

Expected behavior

1.-

If a collection not exist and it is requested, should return a value that indicate this, like: null, undefined, [], etc.... in the best way, that collection, should be created automatically insted of return an error in console (by security reasons maybe)

or 2.-

A method to check if collection exist is expected, like this.firestore.collection(' ').exist() <-- Return boolean

Actual behavior

Throws following error: ERROR FirebaseError: Invalid document reference. Document references must have an even number of segments, but has 1.

Skrigueztep avatar Apr 17 '22 20:04 Skrigueztep

Honestly this doesn't really look like an issue with AngularFire since this is (I think) expected behaviour. You could do it yourself with a try catch. If it errors you can make an empty collection yourself.

NicolasMaas avatar May 07 '22 10:05 NicolasMaas

If someone delete a collection users that have cached elements receive no extra event to invalidate cache data. For example:

    return this.angularFirestore.collection
          path, queryFunction
        ).valueChanges({idField: 'UID'})
        ...

produce only one event containing cached data and will only produce a event again if collection is created. I would appreciate a solution.

RomuloPBenedetti avatar Jul 18 '22 11:07 RomuloPBenedetti