hapi-mongodb-init
Advanced tools
Comparing version 1.0.3 to 1.1.0
@@ -47,3 +47,9 @@ var async = require("async"), | ||
var coll = db.collection(indexData.collection); | ||
coll.ensureIndex(indexData.fields, { name: indexData.name, w: 1 }, function(err){ | ||
var options = { name: indexData.name, w: 1 }; | ||
if(indexData.expireAfterSeconds !== undefined){ | ||
options.expireAfterSeconds = indexData.expireAfterSeconds; | ||
} | ||
coll.ensureIndex(indexData.fields, options, function(err){ | ||
if(err){ | ||
@@ -50,0 +56,0 @@ done(err); |
{ | ||
"name": "hapi-mongodb-init", | ||
"version": "1.0.3", | ||
"version": "1.1.0", | ||
"description": "initialises mongo db connections for hapi", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -163,2 +163,47 @@ describe('db-init tests', function(){ | ||
it('should pass through the expireAfterSeconds flag', function(done){ | ||
p.register(plugin, { | ||
dbs: [{ | ||
connectionString: 'mongodb://127.0.0.1/test', | ||
name: 'myconnection', | ||
indexes: [ | ||
{ | ||
collection: 'mycoll', | ||
name: 'myfield_1', | ||
fields: { | ||
myfield: 1 | ||
}, | ||
expireAfterSeconds: 60 | ||
} | ||
] | ||
}], | ||
mongo: fakeMongo | ||
}, function(err){ | ||
ensuredIndexes[0].names.expireAfterSeconds.should.eql(60); | ||
done(err); | ||
}); | ||
}); | ||
it('should not set expireAfterSeconds when it is not present in the config', function(done){ | ||
p.register(plugin, { | ||
dbs: [{ | ||
connectionString: 'mongodb://127.0.0.1/test', | ||
name: 'myconnection', | ||
indexes: [ | ||
{ | ||
collection: 'mycoll', | ||
name: 'myfield_1', | ||
fields: { | ||
myfield: 1 | ||
}, | ||
} | ||
] | ||
}], | ||
mongo: fakeMongo | ||
}, function(err){ | ||
(ensuredIndexes[0].names.expireAfterSeconds === undefined).should.eql(true); | ||
done(err); | ||
}); | ||
}); | ||
it('should not manage indexes when config is turned off', function(done){ | ||
@@ -165,0 +210,0 @@ p.register(plugin, { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
16273
407