Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

84
Visualizações
ref2.orderByChild is not a function

I'm trying to delete some data from firebase realtime database after some time but gives me this error: Uncaught TypeError: ref2.orderByChild is not a function

this is the code:

import { initializeApp } from "https://www.gstatic.com/firebasejs/9.8.1/firebase-app.js";
import {getDatabase, ref, child, onValue, get} from "https://www.gstatic.com/firebasejs/9.8.1/firebase-database.js"
import "https://cdn.jsdelivr.net/npm/seamless-scroll-polyfill@latest/lib/bundle.min.js";
const firebaseConfig = {
  apiKey: "xxxxx",
  authDomain: "xxxxx",
  databaseURL: "xxxxx",
  projectId: "xxxxx",
  storageBucket: "xxxxx",
  messagingSenderId: "xxxxx",
  appId: "xxxxx"
};
const app = initializeApp(firebaseConfig);
const db = getDatabase();

var ref2 = ref(db, "/2021-2022/Pentamestre/Voti/Novità");
var now = Date.now();
var cutoff = now - 2 * 60 * 60 * 1000;
var old = ref2.orderByChild('timestamp').endAt(cutoff).limitToLast(1);
var listener = old.on('child_added', function(snapshot) {
  snapshot.ref.remove();
});

Obviously in firebaseConfig the datas are presents, i only hidden them here

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

There's a top level function query() in the new Modular SDK to build a Query. Similarly, orderByChild() and other query constraints are also a function. Try refactoring the code as shown below:

var old = query(ref2, orderByChild('timestamp'), endAt(cutoff), limitToLast(1));

var listener = onChildAdded(old, function(snapshot) {
    // ...
});
about 4 years ago · Juan Pablo Isaza Relatório

0

I see you imported "get" but didnt use it, and the ref "/2021-2022/Pentamestre/Voti/Novità" is maybe

"2021-2022/Pentamestre/Voti/Novità"

as path doesnt start with /slash

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda