I am extremely new to Firebase, and I am trying to print my collection to the console.
// Import the functions you need from the SDKs you need
import * as firebase from "firebase/app";
import { initializeApp } from "firebase/app";
import {getFirestore, collection, getDocs} from "firebase/firestore"
const firebaseConfig = {
apiKey: "AIzaSyA1zo9ci0RXQYBxxxxxxxxx",
authDomain: "xxxxx.firebaseapp.com",
databaseURL: "https://xxxxxx-default-rtdb.firebaseio.com",
projectId: "xxxxxx",
storageBucket: "xxxxx.appspot.com",
messagingSenderId: "380xxxxx",
appId: "1:38065xxxxxx:web:5f49bf6dxxxxxxx5",
//measurementId: "G-TYX10C1CBE"
};
// Initialize Firebase
initializeApp(firebaseConfig)
//init services
const db = getFirestore();
//collection ref
const colRef = collection(db, 'Achievements')
//get collection data
getDocs(colRef)
.then((snapshot) => {
console.log(snapshot.docs)
})
The above code is returning: Array []
to the console, and I am unsure why.
In case it's relevant, here are my rules:
// Allow read/write access to all users under any conditions
// Warning: **NEVER** use this rule set in production; it allows
// anyone to overwrite your entire database.
service cloud.firestore {
match /databases/{database}/documents {
match /{document=**} {
allow read, write: if true;
}
}
}
I changed it to this after having trouble retrieving data.