【问题标题】:object mongodb is not a member of package com对象 mongodb 不是包 com 的成员
【发布时间】:2016-04-07 14:54:04
【问题描述】:

运行后我得到这个对象 mongodb is not a member of package com in Play 我解决不了那个问题。我正在尝试从客户端 Scala.js 玩 Scala MongoDB 我的 build.sbt 是 >

lazy val server = (project in file("server")).settings(
  scalaVersion := scalaV,
  scalaJSProjects := clients,
  pipelineStages := Seq(scalaJSProd, gzip),
  resolvers += "scalaz-bintray" at "https://dl.bintray.com/scalaz/releases",
  libraryDependencies ++= Seq(
    "com.vmunier" %% "play-scalajs-scripts" % "0.3.0",
    "org.mongodb" %% "casbah" % "3.1.0",
    "org.webjars" % "jquery" % "1.11.1",
    "com.novus" %% "salat" % "1.9.9",
    "se.radley" %% "play-plugins-salat" % "1.5.0",
    "commons-codec" % "commons-codec" % "1.6",
    specs2 % Test

目标代码

package model

import com.mongodb.DBObject
import com.mongodb.casbah.MongoConnection
import com.mongodb.casbah.commons.MongoDBObject

/**
  * Created by qqQQaAs on 2016-01-04.
  */
object AllBooks {

  def toJson() {
    val collection = MongoConnection()("books")("books")
    val query = "Krakow"
    // simply convert the result to a string, separating items with a comma
    // this string goes inside an "array", and it's ready to hit the road
    val json = "[%s]".format(
      collection.find(query).toList.mkString(",")
    )
  }

控制器

package controllers


import com.mongodb.casbah._
import model.AllBooks
import play.api.mvc._
import shared.SharedMessages

object Application extends Controller {

  def index = Action {
    Ok(views.html.index(SharedMessages.itWorks))
  }

  def service() = Action {

    val json = AllBooks.toJson()

    Ok(json).as("application/json")

  }
}

感谢大家的帮助

【问题讨论】:

    标签: mongodb scala playframework-2.0


    【解决方案1】:

    请按照官方documentation导入以下页面:

    import org.mongodb.scala._
    import org.bson._
    

    【讨论】:

      猜你喜欢
      • 2018-09-10
      • 2020-11-17
      • 2016-08-11
      • 1970-01-01
      • 2019-08-11
      • 2013-02-27
      • 2022-01-01
      • 2018-02-21
      • 2012-12-20
      相关资源
      最近更新 更多