This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| FROM mongo:4.0 | |
| # files used to initialize the database | |
| COPY ./init-db.d/ /docker-entrypoint-initdb.d | |
| # add this command to a js file in the init directory | |
| # formatted on newlines for better readability | |
| RUN echo "rs.initiate( | |
| { | |
| _id: 'rs0', |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| com.mongodb.MongoCommandException: | |
| Command failed with error 40573 (Location40573): | |
| 'The $changeStream stage is only supported on replica sets' on server localhost:27017. | |
| The full response is: | |
| { | |
| "ok" : 0.0, | |
| "errmsg" : "The $changeStream stage is only supported on replica sets", | |
| "code" : 40573, | |
| "codeName" : "Location40573" | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| FROM mongo:4.0 | |
| COPY init.js /init.js |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # this assumes that your docker-compose.yml file is located in ./docker | |
| up-db-local: rebuild-mongo | |
| pushd docker &&\ | |
| docker-compose up -d mongo &&\ | |
| popd | |
| rebuild-mongo: | |
| pushd docker &&\ | |
| docker-compose build mongo-seed &&\ | |
| docker-compose up mongo-seed &&\ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import lombok.AllArgsConstructor; | |
| import lombok.Builder; | |
| import lombok.Data; | |
| import lombok.NoArgsConstructor; | |
| import org.springframework.data.mongodb.core.mapping.Document; | |
| @Data | |
| @Builder | |
| @AllArgsConstructor | |
| @NoArgsConstructor |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import lombok.AllArgsConstructor; | |
| import lombok.Builder; | |
| import lombok.Data; | |
| import lombok.NoArgsConstructor; | |
| import org.bson.types.ObjectId; | |
| import org.springframework.data.annotation.Id; | |
| import org.springframework.data.mongodb.core.mapping.Document; | |
| import org.springframework.data.mongodb.core.mapping.Field; | |
| import java.util.ArrayList; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| db.teams.insert( | |
| [ | |
| { | |
| "_id": ObjectId("5d0c18c190d2b33ae629aaa7"), | |
| "name": "HingleMcCringleberry", | |
| "players": [ | |
| {"name": "Nick Chubb", "score": 0}, | |
| {"name": "James Conner", "score": 0}, | |
| {"name": "Julio Jones", "score": 0}, | |
| {"name": "Michael Thomas", "score": 0} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import dev.timjones.reactive.data.model.Team; | |
| import org.bson.types.ObjectId; | |
| import org.springframework.data.mongodb.repository.Query; | |
| import org.springframework.data.mongodb.repository.ReactiveMongoRepository; | |
| import reactor.core.publisher.Mono; | |
| public interface TeamRepository extends ReactiveMongoRepository<Team, ObjectId> { | |
| @Query(value = "{ 'players.name' : ?0 }") | |
| Mono<Team> findDistinctByPlayerName(String playerName); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import com.mongodb.reactivestreams.client.MongoClient; | |
| import com.mongodb.reactivestreams.client.MongoClients; | |
| import org.springframework.context.annotation.Bean; | |
| import org.springframework.data.mongodb.config.AbstractReactiveMongoConfiguration; | |
| import org.springframework.data.mongodb.core.ReactiveMongoTemplate; | |
| import org.springframework.data.mongodb.repository.config.EnableReactiveMongoRepositories; | |
| /** | |
| * Config class to set up necessary components for watching the MongoDB change stream | |
| */ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * Watch for changes to the teams collection | |
| * | |
| * @return a subscription to the change stream | |
| */ | |
| public Flux<Team> watchForTeamCollectionChanges() { | |
| // set changestream options to watch for any changes to the businesses collection | |
| ChangeStreamOptions options = ChangeStreamOptions.builder() | |
| .filter(Aggregation.newAggregation(Team.class, | |
| Aggregation.match( |