Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

83
Views
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 answers
Answer question

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!