-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFirestore.js
82 lines (59 loc) · 2.12 KB
/
Firestore.js
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import { initializeApp } from "firebase/app";
import { getFirestore } from "firebase/firestore";
const firebaseConfig = {
apiKey: "AIzaSyDbk8rfH80RBRWCy7pxphnQjrQwY9dWMcg",
authDomain: "alternate-tech.firebaseapp.com",
databaseURL: "https://alternate-tech-default-rtdb.asia-southeast1.firebasedatabase.app",
projectId: "alternate-tech",
storageBucket: "alternate-tech.appspot.com",
messagingSenderId: "1057930360277",
appId: "1:1057930360277:web:b03619aa1fca5d7002f95c",
measurementId: "G-4H0N4SPPQH"
};
// Initialize Firebase
const app = initializeApp(firebaseConfig);
// Initialize Cloud Firestore and get a reference to the service
const db = getFirestore(app);
//read UserData
import { collection, getDocs } from "firebase/firestore";
const querySnapshot = await getDocs(collection(db, "User"));
querySnapshot.forEach((User_Rank) => {
console.log(`${User_Rank.id} => ${User_Rank.data()}`);
});
import { doc, getDoc } from "firebase/firestore";
var docRef = doc(db, "User", "User_Lessons_Completed");
var docSnap = await getDoc(docRef);
if (docSnap.exists()) {
let User_Lessons_Completed = docSnap.data()
console.log("Document data:", docSnap.data());
} else {
// doc.data() will be undefined in this case
console.log("No such document!");
}
var docRef = doc(db, "User", "User_Points");
var docSnap = await getDoc(docRef);
if (docSnap.exists()) {
let User_Points = docSnap.data()
console.log("Document data:", docSnap.data());
} else {
// doc.data() will be undefined in this case
console.log("No such document!");
}
var docRef = doc(db, "User", "User_Quiz_Points");
var docSnap = await getDoc(docRef);
if (docSnap.exists()) {
let User_Quiz_Points = docSnap.data()
console.log("Document data:", docSnap.data());
} else {
// doc.data() will be undefined in this case
console.log("No such document!");
}
var docRef = doc(db, "User", "User_Rank");
var docSnap = await getDoc(docRef);
if (docSnap.exists()) {
let User_Rank = docSnap.data()
console.log("Document data:", docSnap.data());
} else {
// doc.data() will be undefined in this case
console.log("No such document!");
}