Greetings,
I am using Salat and Casbah to create a user collection in Mongodb, everything works great until I added a unique index on the email field. Now my insert returns a unique id with no actual record added in the DB for existing email addresses. I am new to scala and Casbah/Salat so I apologize if I am asking an obvious question.
here are my collection indexes
db.users.getIndexes()
[
{
"v" : 1,
"key" : {
"_id" : 1
},
"name" : "_id_",
"ns" : "study_test.users"
},
{
"v" : 1,
"unique" : true,
"key" : {
"email" : 1
},
"name" : "users_email",
"ns" : "study_test.users"
}
]
and this is my dao object
object UserDao extends SalatDAO[UserModel, ObjectId](collection = MongoUtil.getCollection("study", "users")) {
val logger = LoggerFactory.getLogger(UserDao.getClass)
val dao = this
UserDao.collection.ensureIndex(DBObject("email" -> 1), "users_email", true)
RegisterJodaTimeConversionHelpers()
def create(userContract: UserContract): Option[ObjectId] = {
val userModel = UserConverter.toModel(userContract)
dao.insert(userModel)
}
and this is the unit test I am running
class User extends Specification{
val logger = LoggerFactory.getLogger("User Test")
sequential
"Insert test" should {
"create new User collection" in {
val user = UserContract("John", "Doe", "
joh...@domain.com", "08/14/1982", "test", "male")
val id = Try(UserDao.create(user)).toOption.flatten
logger.debug("id was " + id)
id must not equalTo None
}
}
}