object mongodb不是package com的成员

时间:2016-01-04 01:29:59

标签: mongodb scala playframework-2.0

运行后我得到这个对象mongodb不是Play中的包com的成员 我无法解决这个问题。我试图玩Scala MongoDB和客户端Scala.js 我的build.sbt是>

function match(obj, tpl) {
    return Object.keys(tpl).reduce(function(collection, key) {
        if (obj.hasOwnProperty(key) && typeof obj[key] === tpl[key]) {
            collection[key] = obj[key];
        }
        return collection;
    }, {});
}

目标代码

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(",")
    )
  }

感谢帮助人员

1 个答案:

答案 0 :(得分:1)

您应该按照官方documentation

导入以下页面
import org.mongodb.scala._
import org.bson._