Skip to content

bilgesunaz/tepkin

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

57 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Tepkin

Build Status Progress

Reactive MongoDB Driver for Scala 2.11 and Java 8 built on top of Akka IO and Akka Streams.

Only MongoDB 3.0+ is supported.

Contributions

Tepkin is a young but very active project and absolutely needs your help. Good ways to contribute include:

  • Raising bugs and feature requests
  • Fixing bugs
  • Improving the performance
  • Adding to the documentation

Scala examples

Obtaining a reference to a collection

val client = MongoClient("mongodb://localhost")
val db = client("tepkin")
val collection = db("mongo_collection_spec")

Insert and update a document

val document = ("name" := "fehmi") ~ ("surname" := "saglam")

implicit val timeout: Timeout = 5.seconds

val future = for {
  insert <- collection.insert(Seq(document))
  update <- collection.update(
    query = ("name" := "fehmi"),
    update = $set("name" := "fehmi can")
  )
} yield update

Insert and find 100K documents

implicit val mat = ActorFlowMaterializer()(client.context)

val documents: Source[List[BsonDocument], Unit] = Source {
  Iterable.tabulate(100) { _ =>
    (1 to 1000).map(i => $document("name" := s"fehmi$i")).toList
  }
}

val result = for {
  insertResult <- collection.insertFromSource(documents).runForeach(_ => ())
  source <- collection.find(BsonDocument.empty)
  count <- source.map(_.size).runFold(0) { (total, size) =>
    total + size
  }
} yield count

Java example

import net.fehmicansaglam.tepkin.api.*;

MongoClient mongoClient = MongoClient.create("mongodb://localhost");
MongoCollection collection = mongoClient.db("tepkin").collection("test");

BsonDocumentBuilder builder = new BsonDocumentBuilder();
builder.addString("name", "fehmi");
BsonDocument document = builder.build();

FiniteDuration timeout = Duration.create(5, TimeUnit.SECONDS);

CompletableFuture<Optional<BsonDocument>> cf = collection
  .insert(document, mongoClient.ec(), timeout)
  .thenCompose(insert -> collection.findOne(mongoClient.ec(), timeout));
Optional<BsonDocument> actual = cf.get(5, TimeUnit.SECONDS);

Give it a try

Current release is 0.1-SNAPSHOT. So you need to add Sonatype Snapshots repository to your build.sbt:

resolvers += "Sonatype Snapshots" at "https://oss.sonatype.org/content/repositories/snapshots/"

If you are a Scala developer then add the following dependency:

libraryDependencies ++= Seq(
  "net.fehmicansaglam" %% "tepkin" % "0.1-SNAPSHOT"
)

If you are a Java developer then add the following dependency:

libraryDependencies ++= Seq(
  "net.fehmicansaglam" %% "tepkin-java" % "0.1-SNAPSHOT"
)

net.fehmicansaglam.tepkin.api package is intended to be used from Java.

About

Reactive MongoDB Driver for Scala and Java 8

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Scala 96.4%
  • Java 3.5%
  • ApacheConf 0.1%