From ba5ed74a5a52e74b9a3e07655a9b85e8b8df4626 Mon Sep 17 00:00:00 2001 From: Timo Ernst Date: Sat, 25 Jul 2015 21:44:57 +0200 Subject: [PATCH] Added unique index for name and email address Name and email address should be unique to keep db consistent. Also, adding an index increases performance for find(). --- index.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/index.js b/index.js index 3b8f1eb..793f085 100644 --- a/index.js +++ b/index.js @@ -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}); }); };