Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/cedrickring/reactor-mongodb

A wrapper built upon the mongodb-async api with Reactor (http://projectreactor.io/)
https://github.com/cedrickring/reactor-mongodb

Last synced: 23 days ago
JSON representation

A wrapper built upon the mongodb-async api with Reactor (http://projectreactor.io/)

Awesome Lists containing this project

README

        

# Reactor MongoDB
A wrapper built upon the mongodb-async api with Reactor (http://projectreactor.io/) written in Kotlin, but fully compatible
with Java (due to `@JvmOverloads`).

## Dependencies

* `org.mongodb::mongodb-driver-async`
* `io.projectreactor::reactor-core`

## Maven

```xml

com.github.cedrickring
reactor-mongodb
1.7

```

## Example Usage

Java:
```java
ReactiveMongoClient client = ReactiveMongoClient.fromURI("mongodb://");
ReactiveDatabase database = client.getDatabase(""); //get a reactive database

//To get a collection, use
ReactiveCollection collection = database.getCollection("");

//or with a specific type
ReactiveCollection collection = database.getCollection("");

//you can also use factory methods known from MongoCollection
collection.withWriteConcern(...).withCodecRegistry(...);

//To find documents in a collection, use
Flux documents = collection.find(Filters.eq("name", "John"));

//then subscribe to it
documents.subscribe(document -> document.getString("name"));

//or use other functions from Flux
documents.map(document -> document.getString("name")).subscribe(...);
```

Kotlin:
```kotlin
val client = ReactiveMongoClient.fromURI("mongodb://")
val database = client.getDatabase("name")

//in Kotlin we have some useful methods to avoid usage of T::class.java
val collection = database.collection("")

//find documents of a specific type
val find: Flux = collection.findWithType(Filters.eq("my", "filter"))

//or without a specified type
val find: Flux = collection.find(...)

//then just subscribe to it
find.subscribe { println(it) }
```