Comparing version 1.2.7 to 1.2.8
@@ -9,3 +9,5 @@ 'use strict'; | ||
mongo = require('mongodb'), | ||
ObjectID = mongo.BSONPure.ObjectID; | ||
mongoVersion = require('mongodb/package.json').version, | ||
isNew = mongoVersion.indexOf('1.') !== 0, | ||
ObjectID = isNew ? mongo.ObjectID : mongo.BSONPure.ObjectID; | ||
@@ -56,3 +58,3 @@ function Mongo(options) { | ||
server = new mongo.ReplSetServers(servers); | ||
server = new mongo.ReplSet(servers); | ||
} else { | ||
@@ -73,3 +75,3 @@ server = new mongo.Server(options.host, options.port, options.options); | ||
self.client = client; | ||
self.store = new mongo.Collection(client, options.collectionName); | ||
self.store = self.db.collection(options.collectionName); | ||
// self.store.ensureIndex({ 'aggregateId': 1, date: 1 }, function() {}); | ||
@@ -137,10 +139,22 @@ if (!err) { | ||
this.store.update({ _id: id, revision: oldRevision }, { _id: id, revision: revision }, { safe: true, upsert: true }, function (err, modifiedCount) { | ||
if (modifiedCount === 0) { | ||
err = new ConcurrencyError(); | ||
debug(err); | ||
if (callback) { | ||
callback(err); | ||
if (isNew) { | ||
if (modifiedCount && modifiedCount.result && modifiedCount.result.n === 0) { | ||
err = new ConcurrencyError(); | ||
debug(err); | ||
if (callback) { | ||
callback(err); | ||
} | ||
return; | ||
} | ||
return; | ||
} else { | ||
if (modifiedCount === 0) { | ||
err = new ConcurrencyError(); | ||
debug(err); | ||
if (callback) { | ||
callback(err); | ||
} | ||
return; | ||
} | ||
} | ||
if (err && err.message && err.message.match(/duplicate key/i)) { | ||
@@ -147,0 +161,0 @@ debug(err); |
@@ -9,3 +9,5 @@ 'use strict'; | ||
mongo = require('mongodb'), | ||
ObjectID = mongo.BSONPure.ObjectID; | ||
mongoVersion = require('mongodb/package.json').version, | ||
isNew = mongoVersion.indexOf('1.') !== 0, | ||
ObjectID = isNew ? mongo.ObjectID : mongo.BSONPure.ObjectID; | ||
@@ -56,3 +58,3 @@ function Mongo(options) { | ||
server = new mongo.ReplSetServers(servers); | ||
server = new mongo.ReplSet(servers); | ||
} else { | ||
@@ -73,3 +75,3 @@ server = new mongo.Server(options.host, options.port, options.options); | ||
self.client = client; | ||
self.store = new mongo.Collection(client, options.collectionName); | ||
self.store = self.db.collection(options.collectionName); | ||
self.store.ensureIndex({ '_commands': 1, '_commands.id': 1, _timeoutAt: 1, _commitStamp: 1, _hash: 1 }, function() {}); | ||
@@ -143,4 +145,10 @@ if (!err) { | ||
this.store.update({ _id: saga._id, _hash: currentHash }, saga, { safe: true }, function(err, modifiedCount) { | ||
if (modifiedCount === 0) { | ||
return callback(new ConcurrencyError()); | ||
if (isNew) { | ||
if (modifiedCount && modifiedCount.result && modifiedCount.result.n === 0) { | ||
return callback(new ConcurrencyError()); | ||
} | ||
} else { | ||
if (modifiedCount === 0) { | ||
return callback(new ConcurrencyError()); | ||
} | ||
} | ||
@@ -147,0 +155,0 @@ if (callback) { callback(err); } |
{ | ||
"author": "adrai", | ||
"name": "cqrs-saga", | ||
"version": "1.2.7", | ||
"version": "1.2.8", | ||
"private": false, | ||
@@ -6,0 +6,0 @@ "main": "index.js", |
@@ -0,1 +1,4 @@ | ||
## [v1.2.8](https://github.com/adrai/node-cqrs-saga/compare/v1.2.7...v1.2.8) | ||
- added mongodb driver 2.x support | ||
## [v1.2.7](https://github.com/adrai/node-cqrs-saga/compare/v1.2.4...v1.2.7) | ||
@@ -2,0 +5,0 @@ - optimize structureParser |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
4014
201975