sql >> Databáze >  >> NoSQL >> MongoDB

pomocí akka streamů procházet sbírkou mongo

Řešení 1:

def changeModelAndInsertToNewCollection(person:Person) : Future[Boolean] ={
//Todo : call mongo api to update the person
???
}

def processPeople()(implicit m: Materializer): Future[Done] = {
val numberOfConcurrentUpdate = 10

val peopleSource: Source[Person, Future[State]] =
  collection
    .find(json())
    .cursor[Person]()
    .documentSource()

peopleSource
  .mapAsync(numberOfConcurrentUpdate)(changeModelAndInsertToNewCollection)
  withAttributes(ActorAttributes.supervisionStrategy(Supervision.restartingDecider))
  .runWith(Sink.ignore)}

Řešení 2: pomocí Alpakka jako akka stream konektor pro mongo

val source: Source[Document, NotUsed] =
MongoSource(collection.find(json()).cursor[Person]().documentSource())

source.runWith(MongoSink.updateOne(2, collection))



  1. Jak můžete odstranit všechny dokumenty ze sbírky pomocí Mongoose?

  2. Mohu se dotazovat MongoDB ObjectId podle data?

  3. Node.js zobrazující obrázky z Mongo's GridFS

  4. Připojte se k hostiteli mongodb z kontejneru dockeru