fs2-mongodb


License

License

MIT
Categories

Categories

Ant Build Tools MongoDB Data Databases
GroupId

GroupId

org.lyranthe
ArtifactId

ArtifactId

fs2-mongodb_2.12
Last Version

Last Version

0.5.0
Release Date

Release Date

Type

Type

jar
Description

Description

fs2-mongodb
fs2-mongodb
Project URL

Project URL

https://github.com/fiadliel/fs2-mongodb
Project Organization

Project Organization

org.lyranthe
Source Code Management

Source Code Management

https://github.com/fiadliel/fs2-mongodb

Download fs2-mongodb_2.12

How to add to project

<!-- https://jarcasting.com/artifacts/org.lyranthe/fs2-mongodb_2.12/ -->
<dependency>
    <groupId>org.lyranthe</groupId>
    <artifactId>fs2-mongodb_2.12</artifactId>
    <version>0.5.0</version>
</dependency>
// https://jarcasting.com/artifacts/org.lyranthe/fs2-mongodb_2.12/
implementation 'org.lyranthe:fs2-mongodb_2.12:0.5.0'
// https://jarcasting.com/artifacts/org.lyranthe/fs2-mongodb_2.12/
implementation ("org.lyranthe:fs2-mongodb_2.12:0.5.0")
'org.lyranthe:fs2-mongodb_2.12:jar:0.5.0'
<dependency org="org.lyranthe" name="fs2-mongodb_2.12" rev="0.5.0">
  <artifact name="fs2-mongodb_2.12" type="jar" />
</dependency>
@Grapes(
@Grab(group='org.lyranthe', module='fs2-mongodb_2.12', version='0.5.0')
)
libraryDependencies += "org.lyranthe" % "fs2-mongodb_2.12" % "0.5.0"
[org.lyranthe/fs2-mongodb_2.12 "0.5.0"]

Dependencies

compile (3)

Group / Artifact Type Version
org.scala-lang : scala-library jar 2.12.7
org.mongodb : mongodb-driver-async jar 3.8.0
co.fs2 : fs2-core_2.12 jar 1.0.0

Project Modules

There are no modules declared in this project.

fs2-mongodb

Library offers a very basic interface to stream results from MongoDB

Installation

Add the following to your build.sbt:

libraryDependencies += "org.lyranthe" %% "fs2-mongodb" % "0.5.0"

Usage

Add to your code:

import org.lyranthe.fs2_mongodb.imports._

Creating a client

There are two ways of creating a Resource[F, com.mongodb.async.client.MongoClient] which will be closed after use:

Mongo.fromUrl[F] This takes a string representing a MongoDB URL (e.g. mongodb://localhost).

Mongo.fromSettings[F] This takes a com.mongodb.MongoClientSettings object, and uses to set up the client (this can include connecting to multiple databases, required authentication information, etc.).

Streaming iterables

When you have a value of type com.mongodb.async.client.MongoIterable, you can turn it into a fs2.Stream[IO, Document] by calling .stream[IO]. You can supply any type (other than IO) if there is a cats.effect.Async typeclass instance available for it.

One common requirement is to change the batch size for requests. This functionality is available on the MongoIterable type, so you can chain a call like .batchSize(1000) before turning it into a stream.

Example

import cats.effect.IO
import fs2._
import org.bson.Document
import org.lyranthe.fs2_mongodb.imports._

val allDocuments: Stream[IO, Document] =
  for {
    conn <- Stream.resource(Mongo.fromUrl[IO]("mongodb://localhost"))
    database = conn.getDatabase("test_db")
    collection = database.getCollection("test_collection")
    document <- collection.find().stream[IO]
  } yield document

Versions

Version
0.5.0
0.4.0
0.3.0
0.2.0
0.1.0
0.0.5
0.0.4
0.0.3
0.0.2
0.0.1