开发者

how can i use lift-mongo-record with play framework?

I want to u开发者_如何学Cse lift-mongodb-record in my play scala project. for using. i need co configure lift-mongodb like this:

import com.mongodb.Mongo
import net.liftweb.mongodb.{MongoIdentifier, MongoDB}

object MainDb extends MongoIdentifier {
  val jndiName = "main"
}

MongoDB.defineDb(MainDb, new Mongo, "test")

where can I put mongodb initialisation, to make this work?


It doesn't actually matters where you install mongodb. You just need to know the host where you installed mongodb and port on which it running. I suppose you are running you app and installed mongo on the local computer. In this case host would be localhost and by default mongo accepts connections on port 27017.

So now, you have all needed information and you need to provide it to lift like this:

MongoDB.defineDb(
    MainDb, 
    new Mongo(new ServerAddress("localhost", 27017)), 
    "test")

It's also not necessarily needed to define new DB identifier (MainDb in your case), you can always you DefaultMongoIdentifier unless you are accessing several DB instances.

In this page you can find more information about mongodb configuration:

http://www.assembla.com/wiki/show/liftweb/Mongo_Configuration


I recommend you to use casbah with play & scala. http://jaredrosoff.com/2011/05/getting-started-with-play-framework-scala-and-casbah/

Regards,

Serdar

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜