Comments (2)
Hello. There is no such thing as dumb questions!
F[_]
in this case is just an abstract type, which potentially can be anything (as long as its implementation has characteristics of Async
). So your impl
method can look like this:
def impl[F[_] : Async](M: MongoClient[F]): VersionRegistry[F] = new VersionRegistry[F] :
def get(beta: String): F[Option[VersionRegistry.Versions]] =
for
db <- M.getDatabase("sdkman")
coll <- db.getCollectionWithCodec[T]("versions")
version <- coll.find(Filter.eq("name", beta)).first
yield version
Furthermore, you don't need to create new database instance on every request; rather than passing a MongoClient, you could pass a MongoCollection instead and this will let you achieve exactly what you need:
def stream[F[_] : Async]: Stream[F, Unit] =
for {
client <- Stream.resource(MongoClient.fromConnectionString("mongodb://localhost:27017"))
database <- Stream.eval(client.getDatabase("sdkman"))
collection <- Stream.eval(database.getCollection("versions"))
versionsAlg = VersionRegistry.impl[F](collection)
...
} yield ()
from mongo4cats.
Hi @Kirill5k, thanks so much for getting back to me and pointing me in the right direction. I managed to get the whole thing working as you suggested (I've pushed my changes to the same repo in case you were curious). One thing I couldn't get working was initialisation of the codec using the mongodriver marcros, but I've just gone for doing a manual transformation from bson to case classes which works fine.
Thanks again!
from mongo4cats.
Related Issues (18)
- Support for Circe HOT 1
- Typo in `witReadConcern` in `MongoCollection` HOT 1
- Question: $facet support in mongo4cats HOT 4
- Potential slowness when converting to a fs2.Stream HOT 1
- ContainerValueReader Unable to read TimeStamp HOT 3
- Mongo 3.6 required, but I don't have that HOT 2
- Exception when using `$slice` in aggregations HOT 4
- Scala 3 & Circe: Can't upgrade since 0.6.8 due to circe HOT 4
- ZIO Json integration HOT 2
- ZClientSessionLive#commitTransaction and #abortTransaction Ignore Result
- Potential connection pool outage HOT 2
- Document id forced to ObjectId HOT 5
- Intellij marks ZMongo usages as errors HOT 4
- Hard to close a session HOT 3
- CirceJsonMapper doesn't support json integers large than MaxLong HOT 8
- Distinct query breaks typed collections HOT 5
- Dispatcher closing prematurely HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mongo4cats.