Skip to content

Commit

Permalink
Added unique index for name and email address
Browse files Browse the repository at this point in the history
Name and email address should be unique to keep db consistent. Also, adding an index increases performance for find().
  • Loading branch information
Timo Ernst committed Jul 25, 2015
1 parent baa6500 commit ba5ed74
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,15 @@ var Adapter = module.exports = function(config) {
MongoClient.connect(url, function(err, database) {
if (err) {throw err; }
that.db = database;

// Create single key indexes for username and email adress so they're both unique and faster to find
// @see http://docs.mongodb.org/manual/core/index-single/
database.collection(that.collection).createIndex({name:1},{unique:true});
database.collection(that.collection).createIndex({email:1},{unique:true});

// This would create a compound index
// @see http://docs.mongodb.org/manual/core/index-compound/
// database.collection(that.collection).createIndex({name:1, email:1},{unique:true});
});

};
Expand Down

0 comments on commit ba5ed74

Please sign in to comment.