How to add MongoDB to Lift WebApp in Eclipse?

I can't add MongoDb to my Lift WebApp. I have added the maven dependency i.e.

<dependency>
  <groupId>net.liftweb</groupId>
  <artifactId>lift-mongodb-record_2.9.1</artifactId>
  <version>2.4</version>
</dependency>

to my pom.xml file, but I still get not found: object mongodb when I try import mongodb._

Here is the code where I get the error (taken from https://www.assembla.com/spaces/liftweb/wiki/Mongo_Configuration)

import net.liftweb._
import mongodb._ // <- Here is the problem
import util.Props
import com.mongodb.{ Mongo, ServerAddress }

object MongoConfig {
  def init: Unit = {
    val srvr = new ServerAddress(
      Props.get("mongo.host", "127.0.0.1"),
      Props.getInt("mongo.port", 27017))
    MongoDB.defineDb(DefaultMongoIdentifier, new Mongo(srvr), "myapp")
  }
}

Answers


You should post the source and the exact error message when asking for help. AFAIK there is no mongodb package or object...

Anyway, here is an example code which works:

import net.liftweb.mongodb.record.{ MongoId, MongoRecord, MongoMetaRecord }
import net.liftweb.record.field.StringField
import net.liftweb.mongodb.record.field.MongoMapField

object Device extends Device with MongoMetaRecord[Device]

class Device private () extends MongoRecord[Device] with MongoId[Device] {
  def meta = Device

  type idType = _id.MyType

  object serial extends StringField(this, "")
  object name extends StringField(this, "")
  object deviceInfo extends MongoMapField[Device, Any](this)
}

Your dependency looks good.


Need Your Help

Setting up GIT for Symfony2 project: why add web/bundles folder to gitignore

git symfony2 gitignore

I am building my first Symfony2 project and I may be confused on the purpose of the web/bundles folder. According to Symfony2 documentation they say this is where static data goes like js libraries...

java.lang.NullPointerException On Button Click

java android error-handling nullpointerexception android-alertdialog

I'm new to programming in Java/for Android and I'm using an AlertDialog and I want to store two strings and increment a counter and then store it in SharedPreferences.