O'Reilly logo

Lift Application Development Cookbook by Gilberto T. Garcia Jr.

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Mapping a MongoDB collection to a Scala class

In the previous recipe, we learned how to connect a Lift application to a MongoDB database. Now, we will learn how to map a collection from MongoDB to a Scala class so we can use it to store and retrieve data into and from the MongoDB collection.

Getting ready

Let's modify the project from the previous recipe because it already has the connection configured.

How to do it...

Carry out the following steps:

  1. Create a file named Contact.scala in the model package using the following code:
    package code.model import net.liftweb.mongodb.record._ import net.liftweb.mongodb.record.field._ import net.liftweb.record.field.StringField class Contact extends MongoRecord[Contact] with ObjectIdPk[Contact] { def meta = Contact ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required