GithubHelp home page GithubHelp logo

Comments (2)

Kirill5k avatar Kirill5k commented on June 15, 2024

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.

marc0der avatar marc0der commented on June 15, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.