Skip to content

Instantly share code, notes, and snippets.

@katowulf
Created January 4, 2016 20:06
Show Gist options
  • Save katowulf/7c02d42101fc06be3fbc to your computer and use it in GitHub Desktop.
Save katowulf/7c02d42101fc06be3fbc to your computer and use it in GitHub Desktop.
Archive data in Firebase 1.x
var Firebase = require('firebase');
var rootRef = new Firebase("https://<YOUR-FIREBASE-APP>.firebaseio.com/");
var archiveRef = rootRef.child('path/to/archive');
var dataRef = rootRef.child('path/to/data');
var archiveTimestamp = Date.now() - 3600; // everything older than an hour
dataRef.orderByChild('<date field>').endAt(archiveTimestamp).once('value', function(snap) {
snap.forEach(function(childSnap) {
archiveRef.child( childSnap.key() ).set( childSnap.val(), function(err) {
if( err ) { console.error(err); }
else { childSnap.ref().remove(); }
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment