MongoDB Shapeless
My trial at using Shapeless with MongoDB
Supported Types
Currently it supports the following types as base properties for case classes.
String
Int
Long
Double
Boolean
org.bson.types.ObjectId
Seq[A]
, whereA
is any of the first sixMap[String, A]
, whereA
is any of the first sixOption[A]
, whereA
is any of the first sixorg.mongodb.scala.bson.collection.immutable.Document
org.mongodb.scala.bson.BsonDocument
Usage
import io.github.shyamsalimkumar.mongodb.shapeless._
case class User(id: String, name: String, age: Int) extends BaseDBModel
val user = User("user-001", "User 01", 50)
val userDocument = user.toDocument
// Document((age,BsonInt32{value=50}), (name,BsonString{value='User 01'}), (_id,BsonString{value='user-001'}))
Note
Any
is not supported so instead of using Map[String, Any]
use either Document
or BsonDocument
. If you use something like Map[String, Any]
it will result in a
compile error looking like the following
Try implementing an implicit BsonDocumentEncoder[io.github.shyamsalimkumar.mongodb.shapeless.models.ModelD]
This error basically means that something in the ModelD
model is not supported