-
Notifications
You must be signed in to change notification settings - Fork 4k
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
[cloud_firestore] Need id generator like createId() function in AngularFire #49
Comments
CollectionReference has an add method which returns an auto-generated ID: https://pub.dev/documentation/cloud_firestore/latest/cloud_firestore/CollectionReference/add.html |
@eugvb Please report if the comment above solved your issue. |
Maybe it is not perfect way, but I persist Document Id inside it. So I need generate id before calling |
I use: Then apply the id within the document and any other documents, then save. There is an issue with both this and add() that is only occurring recently. iOS is creating a different format of id than Android, where they used to be the same. So you may be better off creating your own id system... Edit: I notice this was new to 0.12.7 but is now consistent across iOS and Android in 0.12.8. Unfortunately the new format of id's are no longer chronological so I'm using the old PushIdGenerator for id's that I prefer to be chronological. |
Ok, storing Document Id in itself not good practice. So in this case no need for id generation. But what about transaction or batch writes?
|
Use document without passing a path: |
It is solution, thank you |
I know its late but here is what I did
|
Can this produce a unique ID? I am thinking it would somehow create an ID that already exists. |
Doesn't work on web at the present moment (cloud_firestore: 0.13.7), getting this error: |
In some cases I need generate id before store document in firestore.
In AngularFire there is function
createId()
In Flutter I can
import 'package:cloud_firestore/src/utils/auto_id_generator.dart'
(since 0.12.8, push_id_generator before)and then use
AutoIdGenerator.autoId()
But it's not true way, because I should import implementation files from another package.
The text was updated successfully, but these errors were encountered: