Skip to content

Fir for Add sparse options for index #11

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,13 +158,16 @@ var MongodbDriver = Base.extend({
* @param columns - The columns to add an index on
* @param unique - A boolean whether this creates a unique index
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please also adjust the tags properly.

*/
addIndex: function(collectionName, indexName, columns, unique, callback) {
addIndex: function(collectionName, indexOptions, callback) {

var options = {
indexName: indexName,
columns: columns,
unique: unique
name: indexOptions.name,
columns: indexOptions.columns,
unique: indexOptions.unique
};
if (indexOptions.hasOwnProperty('sparse')) {
options.sparse = indexOptions.sparse
}

return this._run('createIndex', collectionName, options)
.nodeify(callback);
Expand Down Expand Up @@ -313,7 +316,7 @@ var MongodbDriver = Base.extend({
db[command](collection, options.newCollection, callbackFunction);
break;
case 'createIndex':
db[command](collection, options.columns, {name: options.indexName, unique: options.unique}, callbackFunction);
db[command](collection, options.columns, options, callbackFunction);
break;
case 'dropIndex':
db.collection(collection)[command](options.indexName, callbackFunction);
Expand Down
6 changes: 3 additions & 3 deletions test/mongodb_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ vows.describe('mongodb').addBatch({
return this.callback(err);
}

db.addIndex('event', 'event_title', 'title', false, this.callback);
db.addIndex('event', { name: 'event_title', columns: 'title', unique: false, sparse: true }, this.callback);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here

}.bind(this));
},

Expand Down Expand Up @@ -230,7 +230,7 @@ vows.describe('mongodb').addBatch({
return this.callback(err);
}

db.addIndex('event', 'event_title', 'title', false, function(err, data) {
db.addIndex('event', { name: 'event_title', columns: 'title', unique: false }, function(err, data) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Last thing missing here: You have deleted the old tests, but to actually cover the old and new functionality, the old and the new tests have to coexist, rather than one gets rewritten.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But these are internal calls made within the test case hence I changed them to use the updates style. I have also added a separate test case for addIndex for the previous style.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, this wasn't clear from the diff. Please don't adjust tests in the future and instead add directly new ones instead :)


if(err) {
return this.callback(err);
Expand Down Expand Up @@ -299,7 +299,7 @@ vows.describe('mongodb').addBatch({
return this.callback(err);
}

db.addIndex('event', 'event_title', 'title', false, function(err, data) {
db.addIndex('event', { name: 'event_title', columns: 'title', unique: false }, function(err, data) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here


if(err) {
return this.callback(err);
Expand Down