How to create a collection inside a uid document in Firestore using Flutter?

metamonkey

How do you create a sub-collection in Firestore with Flutter based on a dynamic uid?

Architecture should look like this: users (collection) --> UID (document - unique to each user) --> vault (collection) --> credential (document)

I am currently using the implementation below, which obviously when called just creates the architecture I need except for using a string "uid" in place of the dynamic uid of the user as the document that the vault collection resides in. How to change this so that the document('uid') element is the actual uid document of the current user rather than just the string "uid"?

import 'package:mindpass/models/user.dart';
import 'package:cloud_firestore/cloud_firestore.dart';

class DatabaseService {

  final String uid;
  DatabaseService({ this.uid });
  String credential;

  // collection reference
  final CollectionReference vaultCollection = Firestore.instance.collection('users').document('uid').collection('vault');

  Future<void> updateVaultData(String credUN, String timeStamp) async {
    return await vaultCollection.document(credential).setData({
    'credUN': '"aribtraryUN"',
    'timeStamp': Timestamp.now()
  });
  }
Frank van Puffelen

If the user is signed in with Firebase Authentication, you can get their UID with:

var user = await FirebaseAuth.instance.currentUser();
var uid = user.uid;

And then get their vault collection with:

final CollectionReference vaultCollection = Firestore.instance.collection('users').document(uid).collection('vault');

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

How to add map inside document in firestore using flutter?

分類Dev

how to set custom object with document id to a collection in firestore in flutter?

分類Dev

Flutter and Firestore! Set a Collection, a document and a field

分類Dev

Flutter Firebase - How to Add User uid to Document

分類Dev

How to listen for document changes in Cloud Firestore using Flutter?

分類Dev

How to query using unique document id in Firestore from flutter?

分類Dev

How to get sub-collections of every collection in Firestore using Flutter

分類Dev

Flutter and Firestore: How can access variables from Stateful Widget to create a new document?

分類Dev

How to create empty collection in Firestore Swift

分類Dev

How to get all of the collection ids from document on Firestore?

分類Dev

Deleting document from cloud_firestore in flutter

分類Dev

Firestore/Flutter: querying document's subcollection

分類Dev

Firebase get document length inside collection

分類Dev

Flutter Firestore: How to avoid conflicts in writing/updating a document that is available to multiple users at the same time?

分類Dev

How to import collection and nested collection data in cloud firestore using node js?

分類Dev

How to show collection list in firestore?

分類Dev

How to create array in array using collections and sub collections in Firestore?

分類Dev

How to create a new field in firestore using cloud functions?

分類Dev

how to create an id within the embedded document using mongoDB and spring data

分類Dev

How to create document with subcollection

分類Dev

How to get UID from an Angular fire store Document without snapshot

分類Dev

Flutter video_player with URL from Firestore Document

分類Dev

Flutter:FirestoreはStreamBuilder内でユーザーuidを取得します

分類Dev

how to get the Uid inside a child and another push ID child

分類Dev

Cloud Firestore: how to reference another document?

分類Dev

Firestore update with merge - how to overwrite a part of the document

分類Dev

How to prevent unnecessary Document read in Firestore?

分類Dev

How to update the propriety of a field objects in a firestore document?

分類Dev

Adding an Object to Cloud Firestore using Flutter

Related 関連記事

  1. 1

    How to add map inside document in firestore using flutter?

  2. 2

    how to set custom object with document id to a collection in firestore in flutter?

  3. 3

    Flutter and Firestore! Set a Collection, a document and a field

  4. 4

    Flutter Firebase - How to Add User uid to Document

  5. 5

    How to listen for document changes in Cloud Firestore using Flutter?

  6. 6

    How to query using unique document id in Firestore from flutter?

  7. 7

    How to get sub-collections of every collection in Firestore using Flutter

  8. 8

    Flutter and Firestore: How can access variables from Stateful Widget to create a new document?

  9. 9

    How to create empty collection in Firestore Swift

  10. 10

    How to get all of the collection ids from document on Firestore?

  11. 11

    Deleting document from cloud_firestore in flutter

  12. 12

    Firestore/Flutter: querying document's subcollection

  13. 13

    Firebase get document length inside collection

  14. 14

    Flutter Firestore: How to avoid conflicts in writing/updating a document that is available to multiple users at the same time?

  15. 15

    How to import collection and nested collection data in cloud firestore using node js?

  16. 16

    How to show collection list in firestore?

  17. 17

    How to create array in array using collections and sub collections in Firestore?

  18. 18

    How to create a new field in firestore using cloud functions?

  19. 19

    how to create an id within the embedded document using mongoDB and spring data

  20. 20

    How to create document with subcollection

  21. 21

    How to get UID from an Angular fire store Document without snapshot

  22. 22

    Flutter video_player with URL from Firestore Document

  23. 23

    Flutter:FirestoreはStreamBuilder内でユーザーuidを取得します

  24. 24

    how to get the Uid inside a child and another push ID child

  25. 25

    Cloud Firestore: how to reference another document?

  26. 26

    Firestore update with merge - how to overwrite a part of the document

  27. 27

    How to prevent unnecessary Document read in Firestore?

  28. 28

    How to update the propriety of a field objects in a firestore document?

  29. 29

    Adding an Object to Cloud Firestore using Flutter

ホットタグ

アーカイブ