Skip to content

Commit

Permalink
Merge pull request #47 from mongodb-js/vkarpov15-patch-1
Browse files Browse the repository at this point in the history
fix: use createIndex() instead of deprecated ensureIndex()
  • Loading branch information
vkarpov15 committed Oct 9, 2017
2 parents 107e767 + 981807a commit 0e8d9ba
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ module.exports = function(connect) {

db.
collection(options.collection).
ensureIndex({ expires: 1 }, { expireAfterSeconds: 0 }, function(error) {
createIndex({ expires: 1 }, { expireAfterSeconds: 0 }, function(error) {
if (error) {
var e = new Error('Error creating index: ' + error.message);
return _this._errorHandler(e, callback);
Expand Down
16 changes: 8 additions & 8 deletions test/unit.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ describe('connectMongoDBSession', function() {
beforeEach(function() {
db = strawman({
collection: { argumentNames: ['collection'], chain: true },
ensureIndex: { argumentNames: ['index', 'options', 'callback'] },
createIndex: { argumentNames: ['index', 'options', 'callback'] },
findOne: { argumentNames: ['query', 'callback'] },
remove: { argumentNames: ['query', 'callback'] },
update: { argumentNames: ['query', 'update', 'options', 'callback' ] }
Expand Down Expand Up @@ -68,7 +68,7 @@ describe('connectMongoDBSession', function() {
it('specifying options is optional', function(done) {
var SessionStore = connectMongoDBSession({ Store: StoreStub });
var numIndexCalls = 0;
db.ensureIndex.on('called', function(args) {
db.createIndex.on('called', function(args) {
assert.equal(++numIndexCalls, 1);
assert.equal(args.index.expires, 1);
args.callback();
Expand All @@ -84,7 +84,7 @@ describe('connectMongoDBSession', function() {
it('uses default options and no callback if no args passed', function(done) {
var SessionStore = connectMongoDBSession({ Store: StoreStub });
var numIndexCalls = 0;
db.ensureIndex.on('called', function(args) {
db.createIndex.on('called', function(args) {
assert.equal(++numIndexCalls, 1);
assert.equal(args.index.expires, 1);
args.callback();
Expand Down Expand Up @@ -133,7 +133,7 @@ describe('connectMongoDBSession', function() {
it('handles index errors', function(done) {
var SessionStore = connectMongoDBSession({ Store: StoreStub });
var numIndexCalls = 0;
db.ensureIndex.on('called', function(args) {
db.createIndex.on('called', function(args) {
assert.equal(++numIndexCalls, 1);
assert.equal(args.index.expires, 1);
args.callback(new Error('Index fail'));
Expand All @@ -151,7 +151,7 @@ describe('connectMongoDBSession', function() {
beforeEach(function() {
numIndexCalls = 0;

db.ensureIndex.on('called', function(args) {
db.createIndex.on('called', function(args) {
assert.equal(++numIndexCalls, 1);
assert.equal(args.index.expires, 1);
args.callback();
Expand Down Expand Up @@ -245,7 +245,7 @@ describe('connectMongoDBSession', function() {
beforeEach(function() {
numIndexCalls = 0;

db.ensureIndex.on('called', function(args) {
db.createIndex.on('called', function(args) {
assert.equal(++numIndexCalls, 1);
assert.equal(args.index.expires, 1);
args.callback();
Expand Down Expand Up @@ -300,7 +300,7 @@ describe('connectMongoDBSession', function() {
beforeEach(function() {
numIndexCalls = 0;

db.ensureIndex.on('called', function(args) {
db.createIndex.on('called', function(args) {
assert.equal(++numIndexCalls, 1);
assert.equal(args.index.expires, 1);
args.callback();
Expand Down Expand Up @@ -419,7 +419,7 @@ describe('connectMongoDBSession', function() {
beforeEach(function() {
numIndexCalls = 0;

db.ensureIndex.on('called', function(args) {
db.createIndex.on('called', function(args) {
assert.equal(++numIndexCalls, 1);
assert.equal(args.index.expires, 1);
args.callback();
Expand Down

0 comments on commit 0e8d9ba

Please sign in to comment.