@anriko

Как добраться до корня базы Realtime Database и получить данные?

пробую так не выходит
делал как тут
https://www.npmjs.com/package/firebase

но не могу понять
что надо поправить чтобы использовать так
firebase.database().ref()или firebase.database().ref("child/path")
// Import the functions you need from the SDKs you need
import { initializeApp } from 'firebase/app';
import { getFirestore, collection, getDocs } from 'firebase/firestore/lite';
import { getStorage } from "firebase/storage";
import { getDatabase, ref, set, child, update, remove, query, onValue } from "firebase/database";


// TODO: Add SDKs for Firebase products that you want to use
// https://firebase.google.com/docs/web/setup#available-libraries

// Your web app's Firebase configuration
// тут данные убрал ,а так они есть
const firebaseConfig = {
  apiKey: "",
  authDomain: "",
  databaseURL: "",
  projectId: "",
  storageBucket: "",
  messagingSenderId: "",
  appId: ""
};

// Initialize Firebase
const firebase = initializeApp(firebaseConfig);
export const db = getFirestore(firebase);
async function getCities(db) {
  const citiesCol = collection(db, 'keep');
  const citySnapshot = await getDocs(citiesCol);
  const cityList = citySnapshot.docs.map(doc => doc.data());
  return cityList;
}

// Option 1: Access Firebase services via the defaultProject variable
let defaultStorage = getStorage(firebase);
let defaultFirestore = getFirestore(firebase);

// Option 2: Access Firebase services using shorthand notation
defaultStorage = getStorage();
defaultFirestore = getFirestore();

const database = getDatabase(firebase);
const dbRef = ref("/keep");
const usersSnapshot = get(query(dbRef))
console.log(usersSnapshot);


616b1e01d014c098519780.png
  • Вопрос задан
  • 136 просмотров
Пригласить эксперта
Ответы на вопрос 1
@anriko Автор вопроса
// Import the functions you need from the SDKs you need
import { initializeApp } from 'firebase/app';
import { getFirestore, collection, getDocs } from 'firebase/firestore/lite';
import { getStorage } from "firebase/storage";
import { getDatabase, ref, set, get, child, update, remove, query, onValue } from "firebase/database";

пожоже так
const dbRef = ref(database);
get(child(dbRef, "keeps/sectionlist/")).then((snapshot) => {
  if (snapshot.exists()) { console.log(snapshot.val()); } else {
    console.log("no data found");
  }
}).catch((error) => {
  console.log("unsaccessful error " + error);
});
Ответ написан
Комментировать
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы
19 апр. 2024, в 03:52
1000 руб./за проект
19 апр. 2024, в 03:01
1000 руб./за проект
18 апр. 2024, в 21:56
2000 руб./за проект