Last active
February 25, 2018 05:33
-
-
Save yimengtianya/c933134c17567779338a to your computer and use it in GitHub Desktop.
Wilddog:只获取新增的数据
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
// when the records is empty ,it not work | |
var ref = new Wilddog(...); | |
var first = true; | |
ref.limitToLast(1).on("child_added", function(snap) { | |
if( first ) { | |
first = false; | |
} | |
else { | |
console.log('new record', snap.key()); | |
} | |
}); |
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 ref = new Wilddog(...); | |
ref.once("value", function(snap) { | |
var keys = Object.keys(snap.val()||{}); | |
var lastIdInSnapshot = keys[keys.length-1] | |
ref.orderByKey().startAt(lastIdInSnapshot).on("child_added", function(newMessSnapshot) { | |
if( snap.key() === lastIdInSnapshot ) { return; } | |
console.log('new record', newMessSnapshot.key()); | |
}) | |
}) |
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
// assumes you add a timestamp field to each record (see Wilddog.ServerValue.TIMESTAMP) | |
// pros: fast and done server-side (less bandwidth, faster response), simple | |
// cons: a few bytes on each record for the timestamp | |
var ref = new Wilddog(...); | |
ref.orderByChild('timestamp').startAt(Date.now()).on('child_added', function(snapshot) { | |
console.log('new record', snapshot.key()); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment