Angular: 7.1.2
Firebase: 5.6.0
AngularFire: 5.1.1
Other (e.g. Ionic/Cordova, Node, browser, operating system):
Steps to set up and reproduce
Example code:
const ref = this.afs.collection(this.collectionRef).doc();
Failing on the following error:
Expected 1 arguments, but got 0.ts(2554)
collection.d.ts(18, 12): An argument for 'path' was not provided.
But should be valid per firebase documentation and source:
Add doc example https://firebase.google.com/docs/firestore/manage-data/add-data
Source definition of doc function https://github.com/firebase/firebase-js-sdk/blob/master/packages/firebase/index.d.ts#L1951
* Errors in the JavaScript console *
ERROR Error: Uncaught (in promise): FirebaseError: [code=invalid-argument]: Function CollectionReference.doc() requires its first argument to be of type non-empty string, but it was: undefined
FirebaseError: Function CollectionReference.doc() requires its first argument to be of type non-empty string, but it was: undefined
Doc reference should be created per firebase documentation
Invalid argument error thrown
path argument should be optional in https://github.com/angular/angularfire2/blob/master/src/firestore/collection/collection.ts#L141
I agree, this should align with the Firebase SDK. A potential workaround is to use a pattern like this:
const id = this.afs.createId();
const ref = this.afs.collection(this.collectionRef).doc(id);
+1 Is this going to be fixed in future releases?
Ran into this earlier as well, had to pass a randomly generated string using date constructors to force creation in the database as a workaround, but was totally caught off guard by this error thrown since it contradicts the docs.
+1
I am getting this error as well, when trying to delete a document, however, it is working in another place in the app, so I am extra confused.
If you鈥檙e getting this error when trying to delete, I think you might be sending an undefined id.
ah yes you were right! Thank you! Because of the type and positioning of the component I needed to access the id differently
undefined id. doc['.key'] wasn't working for me any longer had to go doc.id
What if one does this: .doc('') instead?!
Me I got this error claiming to have been undefined then I first checked if the doc id exists then I passed that line query inside the if statement on truthy. if(id.lenght) ....doc(id);
This will be addressed in 5.2, tossed it in real quick as c2354f8. #2086
Mhh, just updated to @angular/fire 5.2 and firebase 6.2.1, and the problem is still here for me.
I'm getting the following error:
CollectionReference.doc() requires its first argument to be of type non-empty string, but it was: undefined
when trying to set a batch write operation calling "set", with this.afs.collection<Offer>('offers').doc().ref .
The solution given here works for me... But calling an empty doc on a collection works well with the firebase-admin SDK to create new documents (in case of a batch write using "set"for example), I was expecting the same with the JS client....
Here is the bug (line 5) :
````
Workaround :
var id = this.firestore.createId();
var doc = this.firestore.collection('myCollection').doc(id);
It is working for me:
this.db.collection(collectionn).add(obj);
or
this.db.collection(this.collectionMain).doc(this.db.createId()).set(obj)
Most helpful comment
I agree, this should align with the Firebase SDK. A potential workaround is to use a pattern like this: