What is the best way to deal with compsite keys when using Salat with MongoDB?
main Salat developer here.
Like Milan suggested, create a case class for your composite key:
case class FooKey(someRelatedId: String, email: String)case class Foo(@Key("_id") naturalKey: FooKey) { // use @Persist if you want these fields serialized verbatim to Mongo - see https://github.com/novus/salat/wiki/Annotations for details @Persist val email = naturalKey.email @Persist val someRelatedId = naturalKey.someRelatedId}object FooDAO extends SalatDAO[Foo, FooKey](collection = /* some Mongo coll */ )
If you object to "_id" as a field name, you can use a global override in the context to remap "_id" to "naturalKey", or supply ad hoc @Key overrides on each object.
I don't personally like giving the _id a different name in your models as then your Mongo queries must use the serialized key "_id" while all your business logic must use the case class field name ("naturalKey" or whatever), but YMMV.
P.S. Our mailing list is at http://groups.google.com/group/scala-salat - I'll see your question quicker there than Stack Overflow.