Created
January 4, 2016 20:06
-
-
Save katowulf/7c02d42101fc06be3fbc to your computer and use it in GitHub Desktop.
Archive data in Firebase 1.x
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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