本文整理汇总了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
)
}
}
开发者ID:Bastcloa,项目名称:testJenkins,代码行数:32,代码来源:OpenIDInfoDAO.scala
示例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")
}
}
}
开发者ID:edinhodzic,项目名称:kyriakos-rest-micro-service-spray.g8,代码行数:26,代码来源:DbObjectConverterSpec.scala
示例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))
}
}
开发者ID:UKHomeOffice,项目名称:product-catalogue,代码行数:36,代码来源:SalatRepository.scala
示例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))
}
}
开发者ID:chrischivers,项目名称:London-Bus-Tracker-Play-Framework,代码行数:28,代码来源:TFLMongoDBConnection.scala
示例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
}
}
}
开发者ID:jroliveira,项目名称:boo-api,代码行数:36,代码来源:GetTogglesComponent.scala
示例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(_))
}
}
}
开发者ID:jroliveira,项目名称:boo-api,代码行数:27,代码来源:GetUserComponent.scala
示例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)
}
开发者ID:jroliveira,项目名称:boo-api,代码行数:27,代码来源:GetUserSpec.scala
示例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
}
开发者ID:jroliveira,项目名称:boo-api,代码行数:33,代码来源:TestEnvironment.scala
注:本文中的com.mongodb.casbah.commons.MongoDBObject类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论