本文整理汇总了Scala中com.mongodb.casbah.commons.MongoDBObject类的典型用法代码示例。如果您正苦于以下问题:Scala MongoDBObject类的具体用法?Scala MongoDBObject怎么用?Scala MongoDBObject使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了MongoDBObject类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Scala代码示例。
示例1: OpenIDInfoDAO
//设置package包名称以及导入依赖的类
package models.daos
import com.mohiva.play.silhouette.api.LoginInfo
import com.mohiva.play.silhouette.impl.daos.DelegableAuthInfoDAO
import com.mohiva.play.silhouette.impl.providers.OpenIDInfo
import com.mongodb.DBObject
import com.mongodb.casbah.Imports._
import com.mongodb.casbah.commons.MongoDBObject
import models.Database
class OpenIDInfoDAO extends DelegableAuthInfoDAO[OpenIDInfo] with AuthInfoDAO[OpenIDInfo] {
override def data: MongoCollection = Database.db("openIDInfo")
override def loadFromDB(dbAuthInfo: DBObject): OpenIDInfo = {
OpenIDInfo(
Database.loadString(dbAuthInfo, "id"),
dbAuthInfo.getAs[DBObject]("attributes").get.map(e => e._1 -> e._2.toString).toMap
)
}
override def convertToDB(loginInfo: LoginInfo, authInfo: OpenIDInfo): DBObject = {
MongoDBObject(
"providerID" -> loginInfo.providerID,
"providerKey" -> loginInfo.providerKey,
"id" -> authInfo.id,
"attributes" -> authInfo.attributes
)
}
}
示例2: DbObjectConverterSpec
//设置package包名称以及导入依赖的类
package io.$org$.service.$domain;format="lower"$.converter
import com.mongodb.casbah.commons.Imports.DBObject
import com.mongodb.casbah.commons.MongoDBObject
import io.$org$.domain.$domain;format="lower"$.$domain$
import org.specs2.mutable.SpecificationWithJUnit
class DbObjectConverterSpec extends SpecificationWithJUnit {
private val dbObjectConverter: DbObjectConverter = new DbObjectConverter
"Db object converter" should {
"convert a $domain$ to a db object" in {
val dbObject: DBObject = dbObjectConverter.serialise($domain$("some data here"))
dbObject.get("data").toString must beEqualTo("some data here")
}
"convert a db object to a $domain$" in {
val $domain;format="lower"$: $domain$ = dbObjectConverter.deserialise(MongoDBObject.newBuilder
.+=("data" -> "some data here")
.result())
$domain;format="lower"$.data must beEqualTo("some data here")
}
}
}
示例3: SalatRepository
//设置package包名称以及导入依赖的类
package cjp.catalogue.mongo
import com.mongodb.WriteConcern
import com.mongodb.casbah.commons.MongoDBObject
import com.mongodb.casbah.{MongoCollection, MongoDB}
import com.novus.salat._
import com.novus.salat.dao.SalatDAO
import org.bson.types.ObjectId
abstract class SalatRepository[T <: CaseClass](val collectionName: String, getDb: () => MongoDB, mc: Option[MongoCollection] = None)(implicit manifest: Manifest[T], ctx: Context)
extends SalatDAO[T, ObjectId](collection = mc.getOrElse(getDb()(collectionName))) {
def findAll: List[T] = {
find(MongoDBObject.empty).toList
}
def removeAll = {
collection.remove(MongoDBObject.empty)
}
def drop() {
collection.drop()
}
def save(bulk: List[T], wc: WriteConcern = WriteConcern.SAFE) {
bulk.foreach {
super.save(_, wc)
}
}
def findById(id: String): Option[T] = {
findOneById(new ObjectId(id))
}
}
示例4: TFLInsertPolyLineDefinition
//设置package包名称以及导入依赖的类
package database.tfl
import akka.actor.{Actor, ActorRef, Props}
import com.mongodb.casbah.commons.MongoDBObject
import database.{POLYLINE_INDEX_DOCUMENT, POLYLINE_INDEX_COLLECTION, DatabaseCollections, DatabaseInsert}
import com.mongodb.casbah.Imports._
import play.api.Logger
import play.api.libs.concurrent.Akka
import play.api.Play.current
object TFLInsertPolyLineDefinition extends DatabaseInsert{
override protected val collection: DatabaseCollections = POLYLINE_INDEX_COLLECTION
override val supervisor: ActorRef = Akka.system.actorOf(Props[TFLInsertPolyLineDefinitionSupervisor], "TFLUpdatePolyLineSupervisor")
}
class TFLInsertPolyLineDefinitionSupervisor extends Actor {
val dbTransactionActor: ActorRef = context.actorOf(Props[TFLInsertPolyLineDefinition], name = "TFLUpdatePolyLineActor")
override def receive: Actor.Receive = {
case doc1: POLYLINE_INDEX_DOCUMENT => dbTransactionActor ! doc1
}
}
class TFLInsertPolyLineDefinition extends Actor {
val collection = POLYLINE_INDEX_COLLECTION
override def receive: Receive = {
case doc1: POLYLINE_INDEX_DOCUMENT => insertToDB(doc1)
case _ =>
Logger.error("TFL PolyLine Definition Actor received unknown message")
throw new IllegalStateException("TFL PolyLine Definition Actor received unknown message")
}
private def insertToDB(doc: POLYLINE_INDEX_DOCUMENT) = {
TFLInsertPolyLineDefinition.numberDBTransactionsRequested += 1
val query = MongoDBObject(
collection.FROM_STOP_CODE -> doc.fromStopCode,
collection.TO_STOP_CODE -> doc.toStopCode)
val update = $set(collection.POLYLINE -> doc.polyLine)
TFLInsertPolyLineDefinition.dBCollection.update(query, update, upsert = true)
TFLInsertPolyLineDefinition.numberDBTransactionsExecuted += 1
}
}
开发者ID:chrischivers,项目名称:London-Bus-Tracker-Play-Framework,代码行数:51,代码来源:TFLInsertPolyLineDefinition.scala
示例5: TFLMongoDBConnection
//设置package包名称以及导入依赖的类
package database.tfl
import com.mongodb.casbah.commons.MongoDBObject
import com.mongodb.casbah.{MongoCollection, MongoClient}
import database.{DatabaseCollections, PREDICTION_DATABASE}
import play.api.Logger
object TFLMongoDBConnection {
lazy val mc: MongoClient = MongoClient()
lazy val getDatabase = mc(PREDICTION_DATABASE.name)
def getCollection(dbc:DatabaseCollections): MongoCollection = {
val coll = getDatabase(dbc.name)
createIndex(coll, dbc)
Logger.info("Index Info: " + coll.getIndexInfo)
coll
}
def closeConnection() = mc.close()
def createIndex(mongoCollection: MongoCollection, dbc: DatabaseCollections) = {
if (dbc.uniqueIndex) mongoCollection.createIndex(MongoDBObject(dbc.indexKeyList),MongoDBObject("unique" -> true))
else mongoCollection.createIndex(MongoDBObject(dbc.indexKeyList),MongoDBObject("unique" -> false))
}
}
示例6: GetToggles
//设置package包名称以及导入依赖的类
package com.jroliveira.boo.components
import com.jroliveira.boo.infra.data.MongoDbComponent
import com.jroliveira.boo.models.{Toggle, User}
import com.mongodb.casbah.Imports._
import com.mongodb.casbah.commons.MongoDBObject
import salat._
import salat.global._
import scala.concurrent.Future
trait GetTogglesComponent extends Component {
this: MongoDbComponent =>
val getToggles: GetToggles
class GetToggles {
def apply(user: User,
name: Option[String],
tags: Option[Seq[String]]): Future[Seq[Toggle]] = Future {
val builder = MongoDBObject.newBuilder
builder += "user" -> user.name
if (name.isDefined) builder += "name" -> name.get
if (tags.isDefined) builder += ("tags" -> MongoDBObject("$in" -> tags.get))
mongoDb
.collection("toggles")
.find(builder.result)
.map(grater[Toggle].asObject(_))
.toList
}
}
}
示例7: GetUser
//设置package包名称以及导入依赖的类
package com.jroliveira.boo.components
import com.jroliveira.boo.infra.data.MongoDbComponent
import com.jroliveira.boo.models.User
import com.mongodb.casbah.Imports._
import com.mongodb.casbah.commons.MongoDBObject
import salat._
import salat.global._
import scala.concurrent.Future
trait GetUserComponent extends Component {
this: MongoDbComponent =>
val getUser: GetUser
class GetUser {
def apply(name: String): Future[Option[User]] = Future {
mongoDb
.collection("users")
.findOne(MongoDBObject("name" -> name))
.map(grater[User].asObject(_))
}
}
}
示例8: GetUserSpec
//设置package包名称以及导入依赖的类
package com.jroliveira.boo.components
import com.jroliveira.boo.models.User
import com.jroliveira.boo.{BaseSpec, TestEnvironment}
import com.mongodb.casbah.commons.MongoDBObject
import scala.concurrent.Await
import scala.concurrent.duration._
class GetUserSpec extends BaseSpec {
val testEnvironment = new TestEnvironment
"GetUser" should {
testEnvironment
.mongoCollection
.findOne(MongoDBObject("name" -> "jroliveira"))
.returns(Some(MongoDBObject("name" -> "jroliveira")))
val user = get("jroliveira").get
"return name equal to 'jroliveira'" in {
user.name must beEqualTo("jroliveira")
}
}
def get(name: String): Option[User] = Await.result(testEnvironment.getUser(name), Duration.Inf)
}
示例9: TestEnvironment
//设置package包名称以及导入依赖的类
package com.jroliveira.boo
import com.jroliveira.boo.components._
import com.jroliveira.boo.infra.data.MongoDbComponent
import com.mongodb.casbah.commons.MongoDBObject
import com.mongodb.casbah.{MongoCollection, MongoCursor}
import org.specs2.mock.Mockito
class TestEnvironment extends MongoDbComponent
with CreateUserComponent
with GetUserComponent
with GetUsersComponent
with CreateToggleComponent
with GetTogglesComponent
with Mockito {
val mongoCursor: MongoCursor = mock[MongoCursor]
val mongoCollection: MongoCollection = mock[MongoCollection]
mongoCollection find() returns mongoCursor
mongoCollection find MongoDBObject("user" -> "jroliveira") returns mongoCursor
val mongoDb: MongoDb = mock[MongoDb]
mongoDb collection "users" returns mongoCollection
mongoDb collection "toggles" returns mongoCollection
val createToggle = new CreateToggle
val getToggles = new GetToggles
val createUser = new CreateUser
val getUser = new GetUser
val getUsers = new GetUsers
}