Comparing version 1.0.18 to 2.0.0
@@ -287,14 +287,18 @@ 'use strict'; | ||
var shadowCol = this.s.db.collection(this.s.name + '.vermongo'); | ||
var aggregatePipeline = [{ $match: { '_id._id' : id } }]; | ||
version = version || 0; | ||
if (!id) { | ||
throw new Error('The provided id is null or undefined'); | ||
} | ||
if (version <= 0) { | ||
aggregatePipeline.push({ $sort: { '_id._version': -1 } }); | ||
aggregatePipeline.push({ $skip: Math.abs(version) }); | ||
return shadowCol.find({ '_id._id': id }) | ||
.sort({ '_id._version': -1 }) | ||
.skip(Math.abs(version)) | ||
.limit(1) | ||
.nextObject(); | ||
} else { | ||
aggregatePipeline.push({ $match: { '_id._version' : version } }); | ||
return shadowCol.find({ '_id._id': id, '_id._version': version }) | ||
.nextObject(); | ||
} | ||
aggregatePipeline.push({ $limit: 1 }); | ||
return shadowCol.aggregate(aggregatePipeline).nextObject(); | ||
}; | ||
@@ -320,3 +324,3 @@ | ||
if (!id) { | ||
return Promise.reject(new Error('The provided id is null or undefined')); | ||
throw new Error('The provided id is null or undefined'); | ||
} | ||
@@ -335,3 +339,3 @@ | ||
if (!document) { | ||
return Promise.reject(new Error('The requested version doesn\'t exist')); | ||
throw new Error('The requested version doesn\'t exist'); | ||
} | ||
@@ -338,0 +342,0 @@ |
{ | ||
"name": "mongoat", | ||
"version": "1.0.18", | ||
"version": "2.0.0", | ||
"description": "Mongoat is a MongoDb ODM", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -66,9 +66,10 @@ 'use strict'; | ||
// test restore | ||
it('should throw error', | ||
it('should throw error, because of id undefined', | ||
function (done) { | ||
_this.testCol.restore() | ||
.catch(function (err) { | ||
try { | ||
_this.testCol.restore(); | ||
} catch(err) { | ||
expect(err.message).toBe('The provided id is null or undefined'); | ||
done(); | ||
}); | ||
} | ||
}); | ||
@@ -75,0 +76,0 @@ |
Mixed license
License(Experimental) Package contains multiple licenses.
Found 1 instance in 1 package
3634096
54
2320
1