Skip to content

Commit

Permalink
Fix issue with erroring backup methods
Browse files Browse the repository at this point in the history
Please note minified version was not updated
  • Loading branch information
benbahrenburg authored and Christian Sullivan committed Oct 22, 2014
1 parent 29f131a commit 9507491
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions lib/Collection.js
Original file line number Diff line number Diff line change
Expand Up @@ -291,10 +291,11 @@ Collection.prototype.backup = function (backupID,fn) {
Collection.prototype.backups = function (fn) {
var callback = fn||function(){};
var keys = [];
var backups = this.snapshots;
for(var id in backups) {
keys.push({id:id, timestamp:ObjectId.hexToTimestamp(id), data:backups[id]});
keys.push({id:id, data:backups[id]});
}
callback(null,keys);
callback(keys);
return this;
};

Expand All @@ -312,10 +313,13 @@ Collection.prototype.removeBackup = function (backupID,fn) {
return this;
};

Object.size = function(obj) { var size = 0, key; for (key in obj) { if (obj.hasOwnProperty(key)) size++; } return size; };

// Restore the snapshot. If no snapshot exists, raise an exception;
Collection.prototype.restore = function ( backupID, fn ) {
var callback = fn||function(){};
if (!this.snapshots.length){ throw new Error("No current snapshot");}
var snapshotCount = Object.size(this.snapshots);
if (snapshotCount===0){ throw new Error("No current snapshot");}
var backupData = this.snapshots[backupID];
if(!backupData){ throw new Error("Unknown Backup ID "+backupID); }
this.docs = backupData;
Expand Down

0 comments on commit 9507491

Please sign in to comment.