Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- case class SimpleAlbum(
- title: String,
- releaseYear: Int)
- var test = new SimpleAlbum("Mago de oz", 1900)
- implicit object SimpleAlbumWriter extends BSONDocumentWriter[SimpleAlbum] {
- def write(album: SimpleAlbum): BSONDocument = BSONDocument(
- "title" -> album.title,
- "releaseYear" -> album.releaseYear)
- }
- implicit object SimpleAlbumReader extends BSONDocumentReader[SimpleAlbum] {
- def read(doc: BSONDocument): SimpleAlbum = {
- SimpleAlbum(
- doc.getAs[String]("title").get,
- doc.getAs[Int]("releaseYear").get)
- }
- }
- val future = collection1.insert(SimpleAlbumWriter.write(test))
- future.onComplete {
- case Failure(e) => throw e
- case Success(lastError) => {
- println("successfully inserted document with lastError = " + lastError)
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement