Firestore Error: Document Not Found Despite Read Permissions

I’m facing an issue with Firestore in my Flutter application. I’m trying to access a document in my “users” collection using the recipient’s userID, but I keep getting an error [cloud_firestore/not-found] Some requested document was not found. even though I’ve allowed read and write access in my Firestore rules.

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>Future<void> performTransaction(
BuildContext context, double montant, String recipientUserId) async {
String? senderUserId =
FirebaseAuth.instance.currentUser!.uid; // Utiliser le userID Firebase
// Exemple de code Dart pour obtenir un token d'accès Firebase
String? idToken = await FirebaseAuth.instance.currentUser?.getIdToken();
print(idToken);
// Vérifiez que le senderUserId n'est pas null
if (senderUserId == null) {
print('Sender UserID not found.');
return;
}
print('Sender UserID: $senderUserId');
print('Recipient UserID: $recipientUserId');
try {
// Référence au document de l'expéditeur (sender)
DocumentReference senderRef =
FirebaseFirestore.instance.collection('users').doc(senderUserId);
// Référence au document du destinataire (recipient) en utilisant recipientUserId
DocumentReference recipientRef =
FirebaseFirestore.instance.collection('users').doc(recipientUserId);
// Fetch sender document
DocumentSnapshot senderSnapshot = await senderRef.get();
print('Sender document: ${senderSnapshot.data()}');
// Fetch recipient document
DocumentSnapshot recipientSnapshot = await recipientRef.get();
print('Recipient document: ${recipientSnapshot.data()}');
// Vérifiez que les documents existent
if (!senderSnapshot.exists) {
print('Sender document not found: $senderUserId');
throw Exception('Sender not found');
}
if (!recipientSnapshot.exists) {
print('Recipient document not found: $recipientUserId');
throw Exception('Recipient not found');
}
await FirebaseFirestore.instance.runTransaction((transaction) async {
// Réobtenir les snapshots dans la transaction
DocumentSnapshot senderSnapshot = await transaction.get(senderRef);
DocumentSnapshot recipientSnapshot =
await transaction.get(recipientRef);
print('Current User ID: ${FirebaseAuth.instance.currentUser!.uid}');
print('Recipient User ID: $recipientUserId');
double senderBalance = senderSnapshot['balance'];
double recipientBalance = recipientSnapshot['balance'];
// Vérifiez que le solde de l'expéditeur est suffisant
if (senderBalance < montant) {
throw Exception('Insufficient funds');
}
// Mettre à jour les balances
transaction.update(senderRef, {'balance': senderBalance - montant});
transaction
.update(recipientRef, {'balance': recipientBalance + montant});
});
print('Transaction successful');
} catch (e) {
print('Transaction failed: $e');
}
}
</code>
<code>Future<void> performTransaction( BuildContext context, double montant, String recipientUserId) async { String? senderUserId = FirebaseAuth.instance.currentUser!.uid; // Utiliser le userID Firebase // Exemple de code Dart pour obtenir un token d'accès Firebase String? idToken = await FirebaseAuth.instance.currentUser?.getIdToken(); print(idToken); // Vérifiez que le senderUserId n'est pas null if (senderUserId == null) { print('Sender UserID not found.'); return; } print('Sender UserID: $senderUserId'); print('Recipient UserID: $recipientUserId'); try { // Référence au document de l'expéditeur (sender) DocumentReference senderRef = FirebaseFirestore.instance.collection('users').doc(senderUserId); // Référence au document du destinataire (recipient) en utilisant recipientUserId DocumentReference recipientRef = FirebaseFirestore.instance.collection('users').doc(recipientUserId); // Fetch sender document DocumentSnapshot senderSnapshot = await senderRef.get(); print('Sender document: ${senderSnapshot.data()}'); // Fetch recipient document DocumentSnapshot recipientSnapshot = await recipientRef.get(); print('Recipient document: ${recipientSnapshot.data()}'); // Vérifiez que les documents existent if (!senderSnapshot.exists) { print('Sender document not found: $senderUserId'); throw Exception('Sender not found'); } if (!recipientSnapshot.exists) { print('Recipient document not found: $recipientUserId'); throw Exception('Recipient not found'); } await FirebaseFirestore.instance.runTransaction((transaction) async { // Réobtenir les snapshots dans la transaction DocumentSnapshot senderSnapshot = await transaction.get(senderRef); DocumentSnapshot recipientSnapshot = await transaction.get(recipientRef); print('Current User ID: ${FirebaseAuth.instance.currentUser!.uid}'); print('Recipient User ID: $recipientUserId'); double senderBalance = senderSnapshot['balance']; double recipientBalance = recipientSnapshot['balance']; // Vérifiez que le solde de l'expéditeur est suffisant if (senderBalance < montant) { throw Exception('Insufficient funds'); } // Mettre à jour les balances transaction.update(senderRef, {'balance': senderBalance - montant}); transaction .update(recipientRef, {'balance': recipientBalance + montant}); }); print('Transaction successful'); } catch (e) { print('Transaction failed: $e'); } } </code>
Future<void> performTransaction(
      BuildContext context, double montant, String recipientUserId) async {
    String? senderUserId =
        FirebaseAuth.instance.currentUser!.uid; // Utiliser le userID Firebase
    // Exemple de code Dart pour obtenir un token d'accès Firebase
    String? idToken = await FirebaseAuth.instance.currentUser?.getIdToken();
    print(idToken);

    // Vérifiez que le senderUserId n'est pas null
    if (senderUserId == null) {
      print('Sender UserID not found.');
      return;
    }

    print('Sender UserID: $senderUserId');
    print('Recipient UserID: $recipientUserId');

    try {
      // Référence au document de l'expéditeur (sender)
      DocumentReference senderRef =
          FirebaseFirestore.instance.collection('users').doc(senderUserId);

      // Référence au document du destinataire (recipient) en utilisant recipientUserId
      DocumentReference recipientRef =
          FirebaseFirestore.instance.collection('users').doc(recipientUserId);

      // Fetch sender document
      DocumentSnapshot senderSnapshot = await senderRef.get();
      print('Sender document: ${senderSnapshot.data()}');

      // Fetch recipient document
      DocumentSnapshot recipientSnapshot = await recipientRef.get();
      print('Recipient document: ${recipientSnapshot.data()}');

      // Vérifiez que les documents existent
      if (!senderSnapshot.exists) {
        print('Sender document not found: $senderUserId');
        throw Exception('Sender not found');
      }

      if (!recipientSnapshot.exists) {
        print('Recipient document not found: $recipientUserId');
        throw Exception('Recipient not found');
      }

      await FirebaseFirestore.instance.runTransaction((transaction) async {
        // Réobtenir les snapshots dans la transaction
        DocumentSnapshot senderSnapshot = await transaction.get(senderRef);
        DocumentSnapshot recipientSnapshot =
            await transaction.get(recipientRef);

        print('Current User ID: ${FirebaseAuth.instance.currentUser!.uid}');
        print('Recipient User ID: $recipientUserId');

        double senderBalance = senderSnapshot['balance'];
        double recipientBalance = recipientSnapshot['balance'];

        // Vérifiez que le solde de l'expéditeur est suffisant
        if (senderBalance < montant) {
          throw Exception('Insufficient funds');
        }

        // Mettre à jour les balances
        transaction.update(senderRef, {'balance': senderBalance - montant});
        transaction
            .update(recipientRef, {'balance': recipientBalance + montant});
      });

      print('Transaction successful');
    } catch (e) {
      print('Transaction failed: $e');
    }
  }

Despite setting Firestore rules to allow read and write access, I continue to receive a document not found error when trying to access the recipient’s document using their userID (recipientUserId). I’ve verified the existence of the document in the Firestore collection.

I’ve double-checked the Firestore rules, ensured the correctness of the userID, and verified the document’s existence through Firestore console. Is there anything I might be missing or any alternative approaches to troubleshoot this issue effectively?

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật