-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_firestore_data.dart
More file actions
40 lines (31 loc) · 1.2 KB
/
test_firestore_data.dart
File metadata and controls
40 lines (31 loc) · 1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:firebase_auth/firebase_auth.dart';
void main() async {
// Initialize Firebase (this would normally be done in your app)
final auth = FirebaseAuth.instance;
final db = FirebaseFirestore.instance;
// Check if user is authenticated
if (auth.currentUser == null) {
print('User not authenticated');
return;
}
final userEmail = auth.currentUser!.email;
print('Current user: $userEmail');
try {
// Try to fetch investments data
final investmentsRef = db.collection('users').doc('investments').collection(userEmail!);
final dateSnapshot = await investmentsRef.get();
print('Found ${dateSnapshot.docs.length} date documents');
for (final dateDoc in dateSnapshot.docs) {
print('Date document: ${dateDoc.id}');
final entriesRef = dateDoc.reference.collection('entries');
final entriesSnapshot = await entriesRef.get();
print(' Entries: ${entriesSnapshot.docs.length}');
for (final entry in entriesSnapshot.docs) {
print(' Entry: ${entry.id} - ${entry.data()}');
}
}
} catch (e) {
print('Error fetching data: $e');
}
}